Design and Analysis of Algorithms Laboratory (15Csl47)
Design and Analysis of Algorithms Laboratory (15Csl47)
***************************SET I***************************
1. What is an algorithm?
An algorithm is a sequence of unambiguous instructions for solving a problem. i.e., for
obtaining a required output for any legitimate input in a finite amount of time
2. What are important problem types? (or) Enumerate some important types of problems.
1. Sorting 2. Searching
3. Numerical problems 4. Geometric problems
5. Combinatorial Problems 6. Graph Problems
7. String processing Problems
(running time) is executed. Basic operation is the most time consuming operation in the
algorithm’s innermost loop.
T(n) = a n = 1, a a constant
2T (n/2) + n n >1, c a constant
O(1) < O(log n) < O(n) < O(n * log n) < O(n2 ) < O(n3 ) < O(2n )
Big Oh(Worst Case), Big Theta (Average Case), Big Omega(Best Case)
GREEDY METHOD
Greedy method is the most important design technique, which makes a choice that looks best at
that moment. A given ‘n’ inputs are required us to obtain a subset that satisfies some constraints
that is the feasible solution. A greedy method suggests that one candevice an algorithm that
works in stages considering one input at a time.
Given n inputs and we are required to form a subset such that it satisfies some given constraints
then such a subset is called feasible solution.
A feasible solution either maximizes or minimizes the given objective function is called as
optimal solution
To maximize ∑pixi
where m is the bag capacity, n is the number of objects and for each object i wi
4. Specify the algorithms used for constructing Minimum cost spanning tree.
a) Prim’s Algorithm
b) Kruskal’s Algorithm
For a given vertex called the source in a weigted connected graph,find shotrtest paths to all its
other vertices.Dijikstra’s algorithm applies to graph with non-negative weights only.
The algorithm looks at a MST for a weighted connected graph as an acyclic subgraph with |v|-1
edges for which the sum of edge weights is the smallest.
DYNAMIC PROGRAMMING
A multistage graph G =(V,E) is a directed graph in which the vertices are partitioned into K>=2
disjoint sets Vi,1<=i<=k.The multi stage graph problem is to find a minimum
cost paths from s(source ) to t(sink)
Two approach(forward and backward)
O(n3 )
It is cubic
***************************SET II***************************
1) What is the time complexity of linear search?
Θ(n)
2) What is the time complexity of binary search?
Θ(log2 n)
3) What is the major requirement for binary search?
The given list should be sorted.
4) What is binary search?
It is an efficient method of finding out a required item from a given list, provided the list is in
order.
The process is:
1. First the middle item of the sorted list is found.
2. Compare the item with this element.
2. The parental dominance requirement – The key at each node is greater than or equal to the
keys at its children
7) What is height of Binary tree?
It is the longest path from the root to any leaf.
8) What is the time complexity of heap sort?
Θ( n logn)
9) What is Merge Sort?
Merge sort is an O (n log n) comparison-based sorting algorithm. Where the given array is
divided into two equal parts. The left part of the array as well as the right part of the array is
sorted recursively. Later, both the left sorted part and right sorted part are merged into a single
sorted array.
10) Who invented Merge Sort?
John Von Neumann in 1945.
11) On which paradigm is it based?
Merge-sort is based on the divide-and-conquer paradigm.
12) What is the time complexity of merge sort?
n log n.
Only one instance of the sub problem is computed & stored. If the same instance of sub problem
is encountered, the solution is retrieved from the table and never recomputed. Very precisely re -
computations are not preformed.
46) What is a spanning tree ?
A spanning tree of a weighted connected graph is a connected acyclic(no cycles) subgraph (i.e. a
tree)that contains all the vertices of a graph and number of edges is one less than number of
vertices.
47) What is a minimum spanning tree ?
Minimum spanning tree of a connected graph is its spanning tree of smallestweight.
48) Prim’s algorithm is based on which technique.
Greedy technique.
49) Name some of the application greedy technique
They are helpful in routing applications: In the case of network where large number of
computers are connected, to pass the data from one node to another node we can find the shortest
distance easily by this algorithm. Communication Networks: Suppose there are 5 different cities
and we want to establish computer connectivity among them, then we take into the account of
cost factor for communication links. Building a road network that joins n cities with minimum
cost.
50) Does Prim’s Algorithm always yield a minimum spanning tree ?
Yes
51) What is the purose of Floyd’s algoreithm?
- To find the all pair shortest path.
52) What is the time efficiency of floyd’s algorithm?
- It is same as warshall’s algorithm that is θ(n3 ).
53) What is shortest path?
- It is the path which is having shortest length among all possible paths.
54) warshall’s algorithm is optimization problem or non-optimization problem ?
Non-optimization problem
55) For what purpose we use Warshall’s algorithm?
Warshall’s algorithm for computing the transitive closure of a directed graph
56) Warshall’s algorithm depends on which property?
Mamatha A, Asst Prof, Dept of IS E, SVIT Page 11
DESIGN AND ANALYSIS OF ALGORITHMS LABORATORY (15CSL47)
Transitive property
57) what is the time complexity of Warshall’s algorithm?
Time complexity of warshall’s algorithm is θ(n3 ).
58) what is state space tree?
Constructing a tree of choices being made and processing is known as state-spacetree.
Root represents an initial state before the search for solution begins.
60) what are promising and non-promising state-space-tree?
Node which may leads to solution is called promising.
Node which doesn’t leads to solution is called non-promising.
61) What are the requirements that are needed for performing Backtracking?
Complex set of constraints. They are:
i. Explicit constraints.
ii. Implicit constraints.