Daa Questions 2
Daa Questions 2
Daa Questions 2
3. 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
4. Name some basic Efficiency classes
1. Constant 2. Logarithmic 3. Linear 4. nlogn
5. Quadratic 6. Cubic 7. Exponential 8. Factorial
15. What do you mean by time complexity and space complexity of an algorithm?
Time complexity indicates how fast the algorithm runs. Space complexity deals with
extra memory it require. Time efficiency is analyzed by determining the number of
repetitions of the basic operation as a function of input size. Basic operation: the
operation that contributes most towards the running time of the algorithm The running
time of an algorithm is the function defined by the number of steps (or amount of
memory) required to solve input instances of size n.
17. What are the different criteria used to improve the effectiveness of algorithm?
(i) The effectiveness of algorithm is improved, when the design, satisfies the following
constraints to be minimum.
Time efficiency - how fast an algorithm in question runs.
Space efficiency – an extra space the algorithm requires
(ii) The algorithm has to provide result for all valid inputs.
50. what is Merge sort? and Is insertion sort better than the merge sort?
Merge sort is divide and conquer strategy that works by dividing an input array in to
two halves,sorting them recursively and then merging the two sorted halves to get the
original array sorted
Insertion sort works exceedingly fast on arrays of less then 16 elements, though for large
‘n’ its computing time is O(n2).
51. Write a algorithm for straightforward maximum and minimum?
Algorithm straight MaxMin(a,n,max,min)
//set max to the maximum and min to the minimum of a[1:n]
{
max := min: = a[i];
for i = 2 to n do
{
if(a[i] >max) then max: = a[i];
if(a[i] >min) then min: = a[i];
}
}
6. Specify the algorithms used for constructing Minimum cost spanning tree.
a) Prim’s Algorithm
b) Kruskal’s Algorithm
UNIT III
DYNAMIC PROGRAMMING
The General method- All pairs shortest path- Optimal binary tree-
Multistage graphs
1. Write the difference between the Greedy method and Dynamic programming.
Greedy method Dynamic programming
1.Only one sequence of decision is
generated.
1.Many number of decisions are generated.
2.It does not guarantee to give an optimal
solution always.
2.It definitely gives an optimal solution
always.
2. Define dynamic programming.
Dynamic programming is an algorithm design method that can be used when a
solution to the problem is viewed as the result of sequence of decisions. It is technique
for solving problems with overlapping subproblems.
3. What are the features of dynamic programming?
• Optimal solutions to sub problems are retained so as to avoid recomputing of their
values.
• Decision sequences containing subsequences that are sub optimal are not
considered.
• It definitely gives the optimal solution always.
4. What are the drawbacks of dynamic programming?
• Time and space requirements are high, since storage is needed for all level.
• Optimality should be checked at all levels.
5. Write the general procedure of dynamic programming.
The development of dynamic programming algorithm can be broken into a
sequence of 4 steps.
1. Characterize the structure of an optimal solution.
2. Recursively define the value of the optimal solution.
3. Compute the value of an optimal solution in the bottom-up fashion.
4. Construct an optimal solution from the computed information.
6. Define principle of optimality.
It states that an optimal solution to any of its instances must be made up of
optimal solutions to its subinstances.
7. Define multistage graph
A multistage graph G =(V,E) is a directed graph in which the vertices are partitioned
in to 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)
8. Define All pair shortest path problem
Given a weighted connected graph, all pair shortest path problem asks to find the
lengths of shortest paths from each vertex to all other vertices.
9.Define Distance matrix
Recording the lengths of shortest path in n x n matrix is called Distance matrix(D)
10.Define floyd’s algorithm
To find all pair shortest path
The algorithm computes the distance matrix of a weighted graph with n vertices
through series of n by n matrices :D(0)…D(k-1),D(k)…..D(n)
11. State the time efficiency of floyd’s algorithm
O(n3)
It is cubic
12. Define OBST
Dynammic pgmg. Used
If probabilities of searching for elements of a set are known then finding optimal
BST for which the average number of comparisons in a search is smallest
possible.
13. Define catalan number
The total number of binary search trees with n keys is equal to nth catalan
number
C(n)=(2n to n) 1/(n+1) for n>0,c(0)=1
14. State time and space efficiency of OBST
SPACE EFFICIENCY :QUADRATIC
TIME EFFICIENCY : CUBIC.
UNIT 4 AND 5
UNIT IV BACKTRACKING
The General method- Solution space and tree organization- The Eight Queens problem-
Sum of subset problem- Graph coloring- Knapsack problem
The General method- O/I Knapsack problem- Traveling sales person problem-Efficiency
consideration . NP Hard and NP Complete problems - Basic concepts
1. What are the requirements that are needed for performing Backtracking?
To solve any problem using backtracking, it requires that all the solutions satisfy a
complex set of constraints. They are:
i. Explicit constraints.
ii. Implicit constraints.