1. What is Algorithm?
An algorithm is a set of instructions designed to
perform a specific task.
In computer programming, algorithms are often created as functions. These
functions serve as small programs that can be referenced by a larger program. For
example, an image viewing application may include a library of functions that each
use a custom algorithm to render different image file formats. An image editing
program may contain algorithms designed to process image data. Examples of image
processing algorithms include cropping, resizing, sharpening, blurring, red-eye
reduction, and color enhancement.
2. Application of tree.
1. Trees can hold objects that are sorted by their keys. We can insert/delete keys in
moderate time (quicker than Arrays and slower than Unordered Linked Lists).
2. Trees can hold objects that are located by keys that are sequences.
3. A tree can represent a structured object.
4. Trees are used to represent phrase structure of sentences, which is crucial to language
processing programs.
5. An operating system maintains a disk's file system as a tree, where file folders act as
tree nodes:
The tree structure is useful because it easily accommodates the creation and deletion of
folders and files.
3. Complexity of algorithm
Time complexity:
The time complexity of an algorithm is the
amount of time it needs to run to completion
How long does this sorting program run? It possibly takes a very long
time on large inputs (that is many strings) until the program has
completed its work.
In another way…
Time complexity measures the “amount of work” done by the
algorithm during solving the problem in the way is independent on the
implementation and particular input data.
4. Complexity of algorithm
The total number of steps involved in a solution to solve a problem is the
function of the size of the problem , which is measures the problems time
complexity.
5. Complexity of algorithm
Space complexity:
The space complexity of an algorithm is the
amount of memory it needs to run to
completion.
This is essentially the number of memory cells which an algorithm
needs. A good algorithm keeps this number as small as possible.
Space complexity is measured by using polynomial amounts od
memory with in infinite time.
6. What is the difference between Θ(n)
and O(n)?
Θ(n)
1) An algorithm is of Θ(g(n)), it means that
the running time of the algorithm as n
(input size) gets larger is proportional to
g(n).
2) Theta -- asymptotic tight bound (Big-O
and Big-Omega.
3) f(x) = Θ(g(x)) (theta) means that the
growth rate of f(x) is asymptotically
equal to the growth rate of g(x) .
4) Examples: Theta: 10n is Θ(n), Θ(0.1n),
Θ(10n)
-- 2 n = Θ(n)
-- n2 + 2 n + 1 = Θ( n2)
O(n) /Big oh
1. An algorithm is of O(g(n)), it means that the
running time of the algorithm as n gets
larger is at most proportional to g(n).
2. Big-O -- asymptotic upper bound (inclusive)
3. f(x) = O(g(x)) (big-oh) means that the
growth rate of f(x) is asymptotically less
than or equal to the growth rate of g(x).
4. Examples:Big-O: 10n is O(n),
O(0.001*n^1.1), NOT O(999n^0.9).
-- 1 = O(n)
-- n = O(n2)
-- log(n) = O(n)
-- 2 n + 1 = O(n)
7. Distinguish between greedy and
dynamic programming :
Greedy Programming
• A greedy algorithm is an
algorithm that follows the
problem solving heuristic of
making the locally optimal
choice at each stage[1] with
the hope of finding a global
optimum. In many problems, a
greedy strategy does not in
general produce an optimal
solution, but nonetheless a
greedy heuristic may yield
locally optimal solutions that
approximate a global optimal
solution in a reasonable time.
Dynamic programming
• Dynamic programming is quite
simple. In general, to solve a
given problem, we need to solve
different parts of the problem
(subproblems), then combine the
solutions of the subproblems to
reach an overall solution. Often
when using a more naive method,
many of the subproblems are
generated and solved many
times. The dynamic programming
approach seeks to solve each
subproblem only once, thus
reducing the number of
computations.
8. Comparison between bellman ford and dijkstra
algorithm:
Dijkstra’s algorithm is faster than Bellman-Ford’s algorithm
Bellman-Ford algorithm :
1) Bellman-Ford algorithm is a single-
source shortest path algorithm, which
allows for negative edge weight and can
detect negative cycles in a graph.
2) On the other hand, Bellman-Ford
algorithm’s nodescontain only the
information that are related to. This
information allows that node just to
know about which neighbor nodes can it
connect and the node that the relation
come from, mutually.
.
Dijkstra algorithm :
1. Dijkstra algorithm is also
another single-source shortest
path algorithm. However, the
weight of all the edges must be
non-negative.
2. The vertexes in Dijkstra’s
algorithm contain the whole information
of a network. There is no such thing that
every vertex only cares about itself and
its neighbors.