100% found this document useful (1 vote)
14 views

ADA Lab Viva Questions

The document contains a series of questions and answers related to algorithms, covering definitions, design techniques, time complexities, and specific algorithms such as Kruskal's, Prim's, Dijkstra's, and sorting methods. It also discusses concepts like dynamic programming, backtracking, and greedy algorithms, along with their applications and complexities. Additionally, it addresses special problems like the N-Queens problem and provides insights into algorithm analysis using Big O notation and the Master Theorem.

Uploaded by

danish.s1849
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
14 views

ADA Lab Viva Questions

The document contains a series of questions and answers related to algorithms, covering definitions, design techniques, time complexities, and specific algorithms such as Kruskal's, Prim's, Dijkstra's, and sorting methods. It also discusses concepts like dynamic programming, backtracking, and greedy algorithms, along with their applications and complexities. Additionally, it addresses special problems like the N-Queens problem and provides insights into algorithm analysis using Big O notation and the Master Theorem.

Uploaded by

danish.s1849
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Viva Questions and Answers - BCSL404 (Analysis & Design of Algorithms Lab)

Q1. What is an algorithm?

A: An algorithm is a finite set of well-defined instructions to solve a problem or

perform a computation.

Q2. What are common algorithm design techniques?

A: Divide and Conquer, Greedy, Dynamic Programming, Backtracking, and Branch and
Bound etc.

Q3. What is time complexity?

A: Time complexity is a measure of the amount of time an algorithm takes to run,

based on input size.

Q4. What is the difference between worst-case, average-case, and best-case

complexities? A:

- Best-case: Minimum time required.

- Average-case: Expected time over all inputs.

- Worst-case: Maximum time for the largest inputs.

Experiment 1: Kruskals Algorithm

Q5. What is the goal of Kruskals algorithm?

A: To find the minimum cost spanning tree using edge-based greedy approach.

Q6. What data structure is used for cycle detection in Kruskals?


A: Disjoint Set Union (DSU) or Union-Find.

Q7. What is the time complexity of Kruskals

algorithm? A: O(E log E), where E = number of

edges.

Experiment 2: Prims Algorithm

Q8. What is the difference between Prim's and Kruskal's algorithm?

A: Prims grows MST from a starting node using adjacent vertices; Kruskals selects globally

smallest edge.

Q9. What is the time complexity of Prim's algorithm?

A: O(V2) with adjacency matrix; O((V + E) log V) with min-heap.

Experiment 3a: Floyd-Warshall

Q10. Can Floyd-Warshall handle negative

weights? A: Yes, but not negative weight

cycles.

Q11. What is the time complexity of Floyd-

Warshall? A: O(V3)

Experiment 3b: Warshalls Algorithm

Q12. What is the purpose of Warshalls algorithm?

A: To compute the transitive closure of a directed graph using logical operations.


Q13. What operations are used in Warshall's

algorithm? A: Logical OR and AND.

Experiment 4: Dijkstras Algorithm

Q14. Can Dijkstras algorithm be used for negative

weights? A: No, it assumes shortest paths do not

improve once visited.

Q15. What is the time complexity of Dijkstras

algorithm? A: O((V + E) log V) with min-priority

queue.

Experiment 5: Topological Sort

Q16. What is topological sort used for?

A: Scheduling tasks, resolving dependencies in DAGs.

Q17. Can a graph with cycles have a topological

sort? A: No, only DAGs can be topologically

sorted.

Experiment 6: 0/1 Knapsack

Q18. What is the 0/1 Knapsack problem?

A: Selecting items with maximum value without exceeding knapsack capacity.

Q19. What is the time complexity using DP?


A: O(nW), where `n` = items and `W` = capacity.
Experiment 7: Greedy Knapsack

Q20. Is greedy method optimal for 0/1

knapsack? A: No, its only optimal for

fractional knapsack.

Q21. How are items selected in greedy

knapsack? A: By selecting based on

profit/weight ratio.

Experiment 8: Subset Sum

Q22. What is the subset sum problem?

A: Finding a subset whose sum equals a target.

Q23. What is the strategy

used? A: Backtracking with

pruning.

Experiment 9: Selection Sort

Q24. What is the complexity of selection

sort? A: O(n2) in all cases.

Q25. Is selection sort

stable? A: No.

Experiment 10: Quick Sort


Q26. What is the average and worst-case complexity?
A: Average: O(n log n), Worst: O(n2).

Q27. Is quick sort


stable?

A: No.

Experiment 11: Merge Sort

Q28. What is the time complexity of merge

sort? A: O(n log n).

Q29. Is merge sort

stable? A: Yes.

Experiment 12: N-Queens Problem

Q30. What is the objective of the N-Queens problem?

A: Place N queens on an NN board such that no two queens attack each other.

Q31. What is the time complexity using

backtracking? A: O(N!).

Additional Questions

Q32. What is the difference between backtracking and dynamic programming?

A: Backtracking explores possibilities recursively; DP stores results of subproblems.

Q33. What is memoization?


A: Top-down DP to store already computed values.

Q34. What is a greedy algorithm?

A: Algorithm that makes locally optimal choices at each step.

General Algorithm and Complexity Concepts

Q1. What is the difference between an algorithm and a program?

A: An algorithm is a logical step-by-step procedure, while a program is its

implementation in a programming language.

Q2. What is space complexity?

A: It is the amount of memory space required by an algorithm during its execution.

Q3. What is Big O notation?

A: It represents the upper bound of an algorithms running time, used for worst-case
analysis.

Q4. Define asymptotic notations.

A: They describe the behavior of functions for large input sizes: Big-O (upper bound),

Omega (lower bound), and Theta (tight bound).

Q5. What is the Master Theorem?


A: It provides a way to analyze time complexity of divide-and-conquer algorithms.

Greedy Algorithms and MST

Q6. Why are Kruskal's and Prim's algorithms called greedy?

A: Because they make a series of choices that seem best at the moment (locally optimal).

Q7. What is the main condition for a graph to have an

MST? A: The graph must be connected and

undirected.

Q8. How do you detect a cycle in Kruskals

algorithm? A: Using the Union-Find data

structure.

Dynamic Programming and Backtracking

Q9. What is the principle of optimality in dynamic programming?

A: An optimal solution to the problem contains optimal solutions to subproblems.

Q10. In what cases would dynamic programming be preferred over

recursion? A: When the problem has overlapping sub problems and

optimal substructure.

Q11. Why is backtracking inefficient for large problem spaces?

A: Because it explores many possible solutions and may be exponential in complexity.

Q12. What is the key difference between backtracking and


brute-force? A: Backtracking prunes paths early if they are not

promising.
Sorting Algorithms

Q13. Which sorting algorithms are comparison-based?

A: Selection sort, Quick sort, Merge sort, Bubble sort, Heap sort.

Q14. What is the auxiliary space of merge sort?

A: O(n), because it uses additional arrays for merging.

Q15. Why is quick sort not stable?

A: It may change the relative order of equal elements due to swapping.

Q16. Which sorting algorithm is best suited for nearly

sorted data? A: Insertion sort.

Graph Algorithms and Traversals

Q17. What is the key difference between BFS and Dijkstras algorithm?

A: BFS is used in unweighted graphs to find shortest paths; Dijkstra is used for weighted
graphs.

Q18. What is the output of topological sort?

A: A linear ordering of vertices such that for every directed edge u v, u appears before v.

Q19. Can Floyd-Warshall detect negative cycles?

A: Yes, if the diagonal of the distance matrix becomes negative.

Special Problems
Q20. How many solutions exist for the 4-Queens

problem? A: Two distinct solutions (considering

symmetric variations).

Q21. What is the constraint check in N-Queens

problem? A: No two queens in the same row,

column, or diagonal.

You might also like