Daa Two Mark Questions
Daa Two Mark Questions
1. Define 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.
14. Compare the time complexity of quick sort, heap sort, Merge sort and Selection sort.
Analysis Quick Merge Heap Selection
Best O(nlogn) O(nlogn) O(nlogn) O(n2)
Average O(nlogn) O(nlogn) O(nlogn) O(n2)
Worst O(n2) O(nlogn) O(nlogn) O(n2)
8. What are the methods are used to implement the Minimum Spanning Tree?
Prim’s algorithm
Kruskal’s algorithm
UNIT III
1. Define dynamic programming.
Dynamic programming is a method for efficiently solving a broad range of search and optimization
problems which exhibit the characteristics of overlapping sub problems and optimal substructure.
2. What are the applications of dynamic programming?
All pairs shortest path problem (Floyd’s algorithm)
Optimal Binary Search Tree
Multistage Graph
It can be used to determine the shortest path from one specific vertex to all other vertices. Floyd’s
Algorithm is normally applied to weighted graphs, but can be extended to
unweighted graphs simply by assigning a weight of 1 to each edge. Floyd's algorithm runs with a time
complexity of O(n3).
Floyd’s algorithm starts with the weight matrix for the weighted graph.
In the weighted graph, a weight matrix is defined as n×n matrix where
W(i,j)=0 if i=j.
W(i,j)=∞ if there is no edge between i and j.
W(i,j)=“weight of edge”
8. Define distance matrix.
The distance matrix is the square matrix consisting of shortest distances from every vertex Vi to vertex
Vj in floyd’ algorithm.
9. Write an algorithm for all pairs shortest path problem (floyd’s algorithm).
UNIT IV
1. Define backtracking.
Backtracking is a process of searching the solution to the problem by searching the solution space(the
set of all feasible solutions) for the given problem.
4. What is NP?
NP is the set of all decision problems (question with yes-or-no answer) for which the 'yes'-answers can
be verified in polynomial time where n is the problem size, and k is a constant) by a deterministic
Turing machine. Polynomial time is sometimes used as the definition of fast or quickly.
5. What is P?
P is the set of all decision problems which can be solved in polynomial time by a deterministic Turing
machine. Since it can solve in polynomial time, it can also be verified in polynomial time.
Therefore P is a subset of NP.
6. What is NP-Complete?
A problem x that is in NP is also in NP-Complete if and only if every other problem in NP can be
quickly (ie. in polynomial time) transformed into x. In other words:
x is in NP, and
Every problem in NP is reducible to x
7. What is NP-Hard?
NP-Hard are problems that are at least as hard as the hardest problems in NP. Note that NP Complete
problems are also NP-hard. However not all NP-hard problems are NP (or even a
Decision problem), despite having 'NP' as a prefix. That is the NP in NP-hard does not mean 'non
deterministic polynomial time'.