Coursify

Design and Analysis of Algorithms (DAA)

PYQ Analysis & Exam Preparation — Module 3

60 mins

A strategic analysis of 22 exam questions spanning 2022–2024. Module 3 focuses strictly on Graph and Tree Algorithms. Mastery of Dijkstra's, Bellman-Ford, Prim's, Kruskal's, and BFS/DFS will secure up to 30 marks on any paper.

Learning Goals

  • Identify the guaranteed question types: Shortest Path traces (Dijkstra/Bellman-Ford), MST traces, and BFS vs DFS theory.
  • Practice with actual MCQ questions testing algorithm complexities and application domains.
  • Understand the exact table structures required by examiners for tracing shortest path algorithms.

The Exam Blueprint: Module 3 PYQ Deep Analysis (2022–2024)

An analysis of 22 exam questions spanning 2022 to 2024 reveals that Module 3 is highly standardized. The questions revolve around three core pillars: Graph Traversals (BFS/DFS), Shortest Paths, and Minimum Spanning Trees (MST). A new addition in 2024 is the Ford-Fulkerson algorithm for Network Flow.

Complete PYQ Table (22 Questions)

YearQ#MarksTopicType
2022Q1a2Adjacency matrix missing parallel edgesMCQ
2022Q1c2Graph coloring for 2 edgesMCQ
2022Q1d2BFS running time = O(V+E)MCQ
2022Q1g2All Pair Shortest Path = Floyd WarshallMCQ
2023Q1c2Algorithm for MST = Kruskal'sMCQ
2023Q1i2Topological sort complexity = O(V+E)MCQ
2024Q1e2DFS traversal data structure = StackMCQ
2024Q1f2MST algorithm = Prim'sMCQ
2024Q1g2Topological sorting requires DAGMCQ
2024Q1h2Max flow algorithm = Ford-FulkersonMCQ
2022Q3a7MST step-by-step traceNumerical
2022Q4a7Dijkstra's shortest path traceNumerical
2022Q7a7Bellman-Ford algorithm + Negative cyclesTheory
2023Q6a7Bellman-Ford trace on matrix + Time complexityNumerical
2023Q6b7Explain MST + Prim's algorithm stepsTheory
2023Q7a7Differentiate BFS vs DFSTheory
2024Q5a7Compare BFS vs DFS + ApplicationsTheory
2024Q5b7System Design: Algorithm choice based on road lengthsTheory
2024Q6a7Draw graph + BFS pseudo-code + BFS traceTheory+Num
2024Q6b7Dijkstra pseudo-code + traceTheory+Num
2024Q7a7Compare Prim's vs Kruskal's + ComplexitiesTheory
2024Q7b7Ford-Fulkerson max flow traceNumerical

Total marks tracked: 112 marks across 3 years.


Topic Heat Map

Topic202220232024Total Marks
Shortest Paths (Dijkstra, Bellman, Floyd)16M ✅7M ✅14M ✅37M
BFS & DFS Traversals2M ✅9M ✅16M ✅27M
Minimum Spanning Tree (Prim/Kruskal)7M ✅9M ✅9M ✅25M
Network Flow / Ford-Fulkerson9M ✅9M
Topological Sort2M ✅2M ✅4M

The Guaranteed Question Types

1. 🔴 Shortest Path Trace (7–14M) Appeared in ALL 3 years. You must know both Dijkstra’s (for graphs with positive weights) and Bellman-Ford (for negative weights/cycles). Examiners expect to see a step-by-step distance table.

2. 🔴 BFS vs DFS Comparison (7M) Highly predictable theory question. You must compare them across 4 dimensions: data structures used, memory complexity, traversal order, and specific applications.

3. 🟠 Prim's vs Kruskal's MST (7M) Either tracing the MST on a graph (2022) or writing the differences/pseudo-code (2023, 2024).

4. 🟡 Real-World Algorithm Selection (7M) A new trend started in 2024 (e.g., Q5b) where you are given a scenario (like Google Maps) and must justify which graph algorithm to use based on edge weights.

Solved Numericals: How to Structure Your Traces


Strategy 1: The Dijkstra Distance Table

When asked to trace Dijkstra's algorithm (e.g., 2022 Q4a, 2024 Q6b), do not just write the final shortest paths. Draw a table showing the relaxation of edges at each step.

Standard Table Format:

StepVisited Set (S)Unvisited Queue (Q)D(A)D(A)D(B)D(B)D(C)D(C)D(D)D(D)
0{}{A, B, C, D}0\infty\infty\infty
1{A}{B, C, D}010 (A)3 (A)\infty
2{A, C}{B, D}07 (C)311 (C)

Key to scoring full marks: Always write the "parent node" in brackets next to the distance cost, e.g., 10 (A). This shows the exact path taken.


Strategy 2: Bellman-Ford Relaxation

Bellman-Ford requires relaxing ALL edges V1|V| - 1 times. If the graph has 5 vertices, you must show 4 Passes.

Pseudo-code for the trace:

1For i = 1 to 4: 2 For every edge (u, v) with weight w: 3 If D[u] + w < D[v]: 4 D[v] = D[u] + w

You must state: "After Pass 4, we run one more pass to check for negative weight cycles. If any distance updates, a negative cycle exists."


Numerical: Ford-Fulkerson Trace

"Find max flow from S to T. Capacities: S→A=10, S→C=10, A→B=4, A→C=2, C→D=9, B→T=10, D→B=6, D→T=10."

Step-by-step trace format required by examiners:

Path 1: S → A → B → T

  • Bottleneck (min capacity): min(10,4,10)=4\min(10, 4, 10) = 4
  • Update residual graph: Decrease forward edges by 4, increase backward edges by 4.
  • Flow so far = 4

Path 2: S → C → D → T

  • Bottleneck: min(10,9,10)=9\min(10, 9, 10) = 9
  • Update residual graph.
  • Flow so far = 4 + 9 = 13

Path 3: S → A → C → D → B → T

  • Bottleneck: min(104=6,2,99=0 WAIT! C→D is full)\min(10-4=6, 2, 9-9=0 \text{ WAIT! C→D is full}).
  • We must find a valid path in the residual graph. C→D is 0 capacity left.
  • Valid residual path: S → A → C ... (cannot go to D).
  • Can we go D → C (backward edge)? No path to T from C without D.
  • Wait, B has remaining capacity to T (10 - 4 = 6). D has remaining to B (6). D has remaining to T (10 - 9 = 1).
  • Let's trace S → C → D → B → T: Bottleneck min(109=1,99=0)\min(10-9=1, 9-9=0). S→C has 1 remaining. C→D has 0 remaining.
  • Let's look at S → A → C ... C is blocked.

Conclusion format: "No more augmenting paths exist from S to T in the residual graph. Max Flow = sum of flows = 13."

(Note: Always draw the residual graph after each path update to guarantee full marks).

Knowledge Check

Question 1 of 5
Q1Single choice

Which of the following algorithm solves the All Pair Shortest Path problem?

High-Yield Subjective Bank: Structure Your Answers


####Compare and contrast BFS and DFS (7 Marks)**

Answer structure (Table Format):

FeatureBFS (Breadth-First Search)DFS (Depth-First Search)
Data StructureQueue (FIFO).Stack (LIFO / Recursion).
Traversal StrategyLevel by level (visits all neighbors first).Goes deep down a branch until a dead end, then backtracks.
Memory UsageHigh. Must store all nodes at the current level. O(V)O(V).Low. Only stores nodes on the current path. O(h)O(h) where h is depth.
Optimal for...Finding the shortest path in unweighted graphs.Solving maze puzzles, topological sorting, cycle detection.
Time ComplexityO(V+E)O(V + E) using adjacency list.O(V+E)O(V + E) using adjacency list.

####Compare Prim’s and Kruskal’s algorithms (7 Marks)**

Answer structure:

  1. Approach:
    • Prim's: Vertex-based. Starts at a root node and greedily grows the tree by selecting the cheapest edge connected to the current tree.
    • Kruskal's: Edge-based. Sorts all edges globally by weight and adds them to the forest one by one, skipping edges that form a cycle.
  2. Data Structures:
    • Prim's: Uses a Priority Queue (Min-Heap) to find the minimum connected edge.
    • Kruskal's: Uses the Disjoint-Set (Union-Find) data structure to detect cycles.
  3. Graph Suitability:
    • Prim's performs better on dense graphs (lots of edges). Time complexity: O(ElogV)O(E \log V).
    • Kruskal's performs better on sparse graphs. Time complexity: O(ElogE)O(E \log E).

####System Design: Shortest Paths on Google Maps (7 Marks)**

Given a city graph mapping, which algorithm to use?

  1. (i) All roads have equal length:
    • Algorithm: BFS (Breadth-First Search).
    • Reasoning: When weights are equal (or 1), BFS inherently finds the shortest path without the overhead of maintaining a priority queue. It is the most efficient choice O(V+E)O(V+E).
  2. (ii) Roads have varying lengths, but no negative lengths:
    • Algorithm: Dijkstra's Algorithm.
    • Reasoning: Dijkstra is the standard for non-negative weighted graphs. It uses a greedy approach (priority queue) to efficiently find the shortest path in O(ElogV)O(E \log V) time.
  3. (iii) Some roads have negative lengths:
    • Algorithm: Bellman-Ford Algorithm.
    • Reasoning: Dijkstra fails on negative weights because a previously finalized node's distance might decrease later. Bellman-Ford correctly handles negative weights by relaxing all edges V1V-1 times.