PYQ Analysis & Exam Preparation — Module 5
A strategic analysis of exam questions for Advanced Topics (2023–2024). This module is extremely focused on two core areas: Randomized Algorithms (specifically Randomized Quick Sort) and Approximation Algorithms for NP-Hard problems.
Learning Goals
- Understand the mechanics and advantages of Randomized Algorithms.
- Memorize the algorithm and expected time complexity for Randomized Quick Sort.
- Explain the necessity of Approximation Algorithms and trace the Vertex Cover 2-approximation.
The Exam Blueprint: Module 5 PYQ Deep Analysis (2023–2024)
An analysis of the 4 exam questions spanning 2023 to 2024 reveals that Module 5 is the shortest but highly concentrated. Examiners test exactly two concepts: Randomized Algorithms and Approximation Algorithms.
Complete PYQ Table (4 Questions)
| Year | Q# | Marks | Topic | Type |
|---|---|---|---|---|
| 2024 | Q1j | 2 | Randomized algorithms utilize random choices | MCQ |
| 2023 | Q9 | 14 | Short notes: Randomized algorithms (among others) | Theory |
| 2024 | Q9a | 7 | Randomized Quick Sort: Algorithm & Complexity | Theory+Num |
| 2024 | Q9b | 7 | Approximation Algorithms + Vertex Cover | Theory |
Total marks tracked: ~30 marks across 2 years.
Topic Heat Map
| Topic | 2023 | 2024 | Total Marks |
|---|---|---|---|
| Randomized Algorithms & Quick Sort | 7M ✅ | 9M ✅ | 16M |
| Approximation Algorithms (Vertex Cover) | — | 7M ✅ | 7M |
The 2 Guaranteed Question Types
1. 🔴 Randomized Quick Sort (7M) You will be asked to define what a randomized algorithm is, write the pseudocode for Randomized Quick Sort (specifically focusing on the
RANDOMIZED-PARTITIONfunction), and state its expected time complexity.
2. 🟠 Approximation Algorithms for NP-Hard (7M) You must define why approximation algorithms are necessary (because NP-Hard problems take exponential time) and provide the standard 2-approximation algorithm for the Vertex Cover problem.
Algorithm 1: Randomized Quick Sort
- 1Step 1
If the array bounds
pandrare such thatp < r, proceed. Otherwise, return. - 2Step 2
Instead of using
A[r]as the pivot directly, pick a random indexibetweenpandr. SwapA[i]withA[r].i = RANDOM(p, r) \ Exchange A[i] with A[r] \ Return PARTITION(A, p, r) - 3Step 3
Execute the standard Lomuto partition scheme using the newly swapped
A[r]as the pivot. - 4Step 4
Recursively sort the left subarray
(p to q-1)and the right subarray(q+1 to r). - 5Step 5
Worst Case: (Still theoretically possible if the random number generator gets incredibly unlucky every time, though highly improbable). Expected / Average Case: (Because the random pivot ensures balanced partitions on average).
Algorithm 2: Vertex Cover Approximation
- 1Step 1
Create an empty set
Cwhich will hold the vertices for our vertex cover. - 2Step 2
Create a set
E'containing all the edges of the given graphG. - 3Step 3
While
E'is not empty, pick an arbitrary edge(u, v)fromE'. - 4Step 4
Add both endpoints
uandvto our cover setC. - 5Step 5
Remove ALL edges from
E'that are attached to eitheruorv. - 6Step 6
Repeat steps 3-5 until
E'is entirely empty. Return the setC.
Knowledge Check
Randomized algorithms make use of:
High-Yield Subjective Bank: Structure Your Answers
####Approximation Algorithms (7 Marks)**
Answer structure:
-
What are Approximation Algorithms? (2M)
- They are algorithms designed to find near-optimal solutions to complex optimization problems in polynomial time.
- They do not guarantee the exact global optimum, but they guarantee that the solution will be within a specific mathematically proven bound (approximation ratio) of the optimal solution.
-
Why are they important for NP-Hard problems? (2.5M)
- NP-Hard optimization problems (like TSP, Vertex Cover, Knapsack) require exponential time to find the exact optimal solution using brute force or backtracking.
- For real-world applications with large inputs (large ), exponential time is computationally impossible (intractable).
- Approximation algorithms allow us to get a "good enough" solution in very fast, tractable polynomial time .
-
Application to Vertex Cover (2.5M)
- Write out the 2-approximation algorithm (shown in the Step-By-Step block above).
- State the ratio: "This algorithm guarantees a vertex cover that is at most exactly twice the size of the theoretical minimum vertex cover. The approximation ratio ."
####Describe Randomized Algorithms (Part of 7 Marks)**
Answer structure:
- Definition: A randomized algorithm is an algorithm that employs a degree of randomness as part of its logic. It uses a pseudo-random number generator to decide the next step during its execution.
- Las Vegas vs Monte Carlo:
- Las Vegas Algorithm: Always produces the correct answer, but its running time varies randomly (e.g., Randomized Quick Sort).
- Monte Carlo Algorithm: Has a deterministic running time, but there is a small probability that it might produce an incorrect answer (e.g., Karger's Min-Cut, Miller-Rabin primality test).
- Advantage: It prevents "malicious" worst-case inputs from consistently degrading performance. In Randomized Quick Sort, no specific input array can force time every single time the algorithm runs.