DAA inteviwe
DAA inteviwe
Analysis of Algorithms:
1. Basic Concepts
Q6: What is the difference between time complexity and space complexity?
A6: Time complexity measures the number of basic operations an algorithm performs,
while space complexity measures the amount of memory required to execute the
algorithm.
2. Sorting Algorithms
Q17: Why is Quick Sort faster than Merge Sort in practice despite having a
worst-case time complexity of O(n2)O(n^2)?
A17: Quick Sort is often faster because of its smaller constant factors and its ability to
sort in-place, unlike Merge Sort, which requires additional space for merging.
4. Dynamic Programming
Q19: What is the time complexity of the Fibonacci number computation using
dynamic programming?
A19: The time complexity of computing Fibonacci numbers using dynamic
programming is O(n)O(n), as it stores previously computed values to avoid
recalculating them.
Q22: What is the time complexity of the Knapsack Problem using dynamic
programming?
A22: The time complexity of the 0/1 Knapsack Problem using dynamic programming
is O(nW)O(nW), where nn is the number of items and WW is the capacity of the
knapsack.
5. Greedy Algorithms
Q24: What is the time complexity of Kruskal’s algorithm for finding the
minimum spanning tree?
A24: The time complexity of Kruskal’s algorithm is O(Elog E)O(E \log E), where
EE is the number of edges in the graph.
Q25: How does the Greedy algorithm for activity selection work?
A25: The Greedy algorithm for activity selection selects the activity that finishes the
earliest and does not overlap with previously selected activities.
Q28: What is the time complexity of Dijkstra’s algorithm with a priority queue?
A28: The time complexity of Dijkstra’s algorithm with a priority queue (using a
binary heap) is O((E+V)log V)O((E + V) \log V), where VV is the number of
vertices and EE is the number of edges.
6. Backtracking
Q31: What is the time complexity of solving the N-Queens problem using
backtracking?
A31: The time complexity of solving the N-Queens problem using backtracking is
O(N!)O(N!), as there are NN possible positions for each queen.
Q32: How does the backtracking algorithm for the subset-sum problem work?
A32: The backtracking algorithm for the subset-sum problem tries all possible subsets
of a set to check if their sum equals the target. It prunes the search space when the
sum exceeds the target.
7. Graph Algorithms
8. Network Flow
a tree-like data structure used to store a dynamic set of strings, where nodes represent
common prefixes of the strings.
Q60: What is the time complexity of the union-find operations with path
compression and union by rank?
A60: The time complexity of the union and find operations with path compression
and union by rank is nearly constant, O(α(n))O(\alpha(n)), where α\alpha is the
inverse Ackermann function.
Q64: What is the time complexity of matrix multiplication using the Strassen
algorithm?
A64: The time complexity of matrix multiplication using the Strassen algorithm is
O(nlog 27)O(n^{\log_2 7}), which is approximately O(n2.81)O(n^{2.81}), faster
than the standard O(n3)O(n^3) approach.
Q65: What is the difference between polynomial time and exponential time
algorithms?
A65: Polynomial-time algorithms have time complexities that grow at most as a
polynomial function of the input size, while exponential-time algorithms have time
complexities that grow exponentially, making them impractical for large inputs.
Q74: What is the time complexity of Tarjan’s algorithm for finding strongly
connected components?
A74: Tarjan’s algorithm for finding strongly connected components has a time
complexity of O(V+E)O(V + E), where VV is the number of vertices and EE is the
number of edges.
Q78: What is the complexity of solving linear programming problems using the
Simplex algorithm?
A78: The Simplex algorithm has an exponential time complexity in the worst case,
but it often performs well in practice with polynomial-time average case behavior.
Q87: What is the complexity of the Knapsack problem using a greedy algorithm?
A87: The greedy algorithm for the fractional knapsack problem has a time complexity
of O(nlog n)O(n \log n), where nn is the number of items.
This list provides a wide variety of questions covering fundamental concepts and
advanced topics in the design and analysis of algorithms.