Algorithm Design and Analysis (ADA) Viva Questions with Answers
General Viva Questions
1. What is time complexity? How is it measured?
Time complexity is the computational complexity that describes the amount of time it takes to run an
algorithm as a function of the input size. It is measured using Big O notation (e.g., O(n), O(log n)).
2. What is space complexity and why is it important?
Space complexity refers to the amount of memory space required by an algorithm during execution. It is
important to ensure efficient use of memory.
3. What is the difference between brute-force and divide-and-conquer strategies?
Brute-force tries all possible solutions. Divide-and-conquer splits the problem into sub-problems, solves
them recursively, and combines the results.
4. What are worst-case, best-case, and average-case complexities?
• Worst-case: Maximum time taken.
• Best-case: Minimum time taken.
• Average-case: Expected time over all inputs.
5. What is asymptotic notation?
It represents the running time of an algorithm in terms of input size:
• Big O (O): Upper bound.
• Omega (Ω): Lower bound.
• Theta (Θ): Tight bound.
6. What is an algorithm?
An algorithm is a finite sequence of well-defined instructions to solve a problem.
7. What is a recursive algorithm?
An algorithm that solves a problem by calling itself with a smaller sub-problem
8. What is dynamic programming?
A technique used to solve problems by breaking them into subproblems, solving each subproblem once,
and storing the results for reuse.
9. What is greedy algorithm?
An algorithm that makes the locally optimal choice at each step with the hope of finding the global
optimum.
10. Difference between dynamic programming and greedy approach?
Dynamic programming solves overlapping subproblems and stores results; greedy approach makes
decisions based on immediate benefit without considering future consequences.
11. What is a data structure?
A data structure is a way of organizing and storing data so that it can be accessed and modified efficiently.
12. What are common types of data structures used in algorithms?
Arrays, linked lists, stacks, queues, trees, graphs, heaps, and hash tables.
13. What is a graph?
A graph is a data structure consisting of vertices (nodes) connected by edges. It can be directed or
undirected.
14. What is the difference between BFS and DFS?
BFS (Breadth-First Search) explores level by level using a queue; DFS (Depth-First Search) explores as far as
possible along a branch using a stack or recursion.
15. What is a spanning tree?
A spanning tree is a subgraph of a connected graph that includes all vertices and is a tree (no cycles).
16. What is the difference between a tree and a graph?
A tree is an acyclic connected graph with N-1 edges for N vertices. A graph may have cycles and varying
number of edges.
17. What is the difference between a min-heap and max-heap?
In a min-heap, the parent node is smaller than its children; in a max-heap, the parent is larger.
18. What is backtracking?
A general algorithmic technique that incrementally builds candidates and abandons them if they do not
satisfy the problem's constraints.
19. What is memoization?
An optimization technique that stores results of expensive function calls and reuses them when the same
inputs occur again.
20. What is amortized analysis?
It is the average time per operation over a worst-case sequence of operations, ensuring some costly
operations are balanced by many cheap ones.
Program-Specific Viva Questions
Tower of Hanoi
1. What is the recurrence relation for Tower of Hanoi?
T(n) = 2T(n-1) + 1
2. Time complexity of Tower of Hanoi?
O(2^n)
3. Total moves for n disks?
2^n - 1
4. Can it be solved iteratively?
Yes, using a stack or simulation.
Power Function (a^n)
1. Time complexity (brute-force)?
O(n)
2. Divide-and-conquer method?
Exponentiation by squaring. Time complexity: O(log n)
3. Formula used?
If n is even: a^n = (a^(n/2))^2; if odd: a^n = a * a^(n-1)
Binary Search
1. Prerequisite?
Sorted array.
2. Time complexity?
O(log n)
3. Best and worst case?
Best: O(1); Worst: O(log n)
Linear Search
1. How it works?
Sequentially checks each element.
2. When preferred?
When data is unsorted or for small datasets.
3. Time complexity?
O(n)
Warshall’s Algorithm
1. What is transitive closure?
It shows if there is a path between every pair of vertices.
2. Working principle?
Updates the reachability matrix using dynamic programming.
3. Time complexity?
O(n^3)
Polynomial Evaluation
1. What is Horner’s rule?
Efficient evaluation using nested multiplication.
2. Time complexity (Horner’s)?
O(n)
3. Compare brute-force vs Horner’s?
Brute-force: O(n^2); Horner’s: O(n)
Part-B Programs
KMP Algorithm
1. Time complexity?
O(n + m)
2. Purpose of LPS array?
Avoids re-comparison by storing longest proper prefix-suffix.
3. Advantage over naive approach?
Faster by avoiding unnecessary comparisons.
Topological Sort
1. What is it?
Ordering of vertices in a DAG such that for every edge u → v, u comes before v.
2. Can cyclic graph have topological sort?
No.
3. Common data structures used?
Stack and adjacency list.
Selection Sort
1. How it works?
Repeatedly finds the minimum element and places it at the beginning.
2. Time complexity?
O(n^2)
3. Is it stable?
No, unless modified.
Binomial Coefficient
1. Recurrence relation?
C(n, k) = C(n-1, k-1) + C(n-1, k)
2. Use of dynamic programming?
Avoids redundant computation using a table.
3. Pascal’s triangle relation?
Each element is sum of the two above it.
Quick Sort
1. Average and worst-case complexity?
Average: O(n log n); Worst: O(n^2)
2. Why better than O(n^2) sorts?
Faster average performance.
3. Partitioning strategies?
Lomuto and Hoare partition schemes.
Floyd’s Algorithm
1. Difference from Dijkstra’s?
Floyd’s finds all-pairs shortest paths; Dijkstra’s finds single-source shortest path.
2. Time complexity?
O(n^3)
3. Can it handle negative weights?
Yes, but not negative cycles.