Design and Analysis of Algorithms
106502Module 5: Advanced Topics
Q1i. What is the approximation ratio (or performance ratio) of the greedy algorithm for the Vertex Cover problem? (i) 2 (ii) 1.5 (iii) ln n (iv) 120252m
Module 5: Advanced Topics
View this question on its own page →What is the approximation ratio (or performance ratio) of the greedy algorithm for the Vertex Cover problem?
(i) 2
(ii) 1.5
(iii) ln n
(iv) 1Worked SolutionAnswer: (i) 2
Explanation:
Classic 2-approximation for Minimum Vertex Cover (greedy matching-based):
C = ∅ while E ≠ ∅: pick any edge (u,v) ∈ E add both u and v to C remove all edges incident to u or vAny optimal cover must include at least one endpoint of each picked edge, and picked edges are disjoint. So .
Ratio 2 is tight; a simple maximal-matching algorithm achieves it. No polynomial algorithm can achieve unless (inapproximability). The naive greedy "pick highest-degree vertex" can be bad, not 2.
Correct choice: (i) 2
Q1j. Randomized algorithms make use of: (i) Deterministic input (ii) Random choices during execution (iii) Recursive backtracking (iv) Fixed input-output pairs20242m
Module 5: Advanced Topics
View this question on its own page →Randomized algorithms make use of:
(i) Deterministic input
(ii) Random choices during execution
(iii) Recursive backtracking
(iv) Fixed input-output pairsWorked SolutionAnswer: (ii) Random choices during execution
Explanation:
- Randomized algorithms use a random number generator to make decisions; behavior is probabilistic.
- Types: Las Vegas (always correct, random running time, e.g., Randomized QuickSort) vs Monte Carlo (may be incorrect with bounded probability, e.g., Miller-Rabin primality).
- Random choices help avoid worst-case inputs (Randomized QuickSort expected ) or achieve simplicity/probabilistic guarantees.
Correct choice: (ii)
Q7a. Explain the approximation algorithm for the travelling salesman problem.20257m
Module 5: Advanced Topics
View this question on its own page →Explain the approximation algorithm for the travelling salesman problem.
Worked SolutionApproximation Algorithm for TSP (Metric TSP — 2-Approximation)
For general TSP (arbitrary distances) no polytime approximation exists unless (Hamiltonian cycle reduces). For Metric TSP (complete graph satisfying triangle inequality ) a constant-factor approximation exists.
2-Approximation via MST ( MST-doubling )
Approx-TSP(G, c): T = MST(G) // via Prim/Kruskal Perform preorder walk of T (DFS) starting at arbitrary root, list vertices in order of first visit Return Hamiltonian cycle visiting in that order + return to start (shortcutting repeated vertices using triangle inequality)Analysis: Let OPT = optimal TSP tour cost. Removing one edge from OPT gives spanning tree → . Full walk of T traverses each edge twice → . Shortcutting via triangle inequality can only decrease cost → → 2-approximation. Time or .
Christofides 1.5-Approximation (better)
- Find MST .
- Find minimum weight perfect matching on vertices of with odd degree (even number, via Blossom ).
- Combine (Eulerian multigraph, all vertices even degree).
- Find Euler tour, shortcut to Hamiltonian cycle.
Ratio: , → .
Heuristic without guarantee: Nearest Neighbor, 2-opt local search.
Q7b. Discuss the steps to find approximate solutions to NP-Hard optimization problems using approximation algorithms with an example.20257m
Module 5: Advanced Topics
View this question on its own page →Discuss the steps to find approximate solutions to NP-Hard optimization problems using approximation algorithms with an example.
Worked SolutionApproximation for NP-Hard Optimization — General Steps + Example
Why Approximation?
NP-hard optimization (e.g., TSP, Vertex Cover, Set Cover, Knapsack) no known polytime exact solution (if $P
eq NP$). Approximation algorithms give near-optimal feasible solution in polytime with proven ratio guarantee.General Steps
- Formulate optimization: Min or Max objective (e.g., min vertex cover size, min tour length).
- Check complexity: Prove NP-hard (reduction from known NP-hard). → motivates approximation.
- Design polytime heuristic: Often greedy, DP relaxation, LP rounding, MST/matching, local search.
- Prove approximation ratio :
- For minimization:
- For maximization:
Show bound via lower bound on OPT (e.g., LP optimum ≤ OPT, MST ≤ TSP OPT) and upper bound on ALG.
- Analyze time: Must be polytime (e.g., , ).
- Tighten: Improve ratio or show hardness of better approximation (inapproximability).
Example: Minimum Vertex Cover — 2-Approximation
Input graph , goal min vertices covering all edges.
Algorithm (matching-based, as in Q84):
C=∅; E' = E while E'≠∅: pick arbitrary (u,v)∈E' C = C ∪ {u,v} remove all edges incident to u or v from E' return CProof of ratio 2: Let be set of edges picked (matching, disjoint). Any vertex cover must include ≥1 endpoint per edge in → . Algorithm includes both endpoints → .
Example graph: Triangle . picks → size2, OPT=2 (any 2 cover) ratio1. Star center+leaves: picks center-leaf → size2 vs OPT1 → ratio2 tight.
Time .
Other examples: Metric TSP 2-approx via MST (Q96), Knapsack FPTAS, Set Cover greedy.
Importance: Provides usable solutions with guarantee where exact is infeasible.
Q8b. Explain the Bin Packing Problem using heuristic techniques such as: * First Fit * Best Fit * Next Fit20257m
Module 5: Advanced Topics
View this question on its own page →Explain the Bin Packing Problem using heuristic techniques such as:
- First Fit
- Best Fit
- Next Fit
Worked SolutionBin Packing Problem & Heuristics
Problem
Given items sizes (bin capacity 1) or integer capacity , pack into minimum number of bins. Decision version NP-complete (reduction from Partition), optimization NP-hard. No known polytime exact → heuristics & approximation.
Heuristics (online — items appear one by one)
First Fit (FF): For each item in given order, place in first bin where it fits (scanning bins in order); if none, open new bin.
- Time or O(n·#bins).
- Approximation: (Johnson), uses at most bins.
Best Fit (BF): Place item in bin where it leaves smallest leftover space that still fits (tightest fit); if none, new bin.
- Also ~1.7 approx. Often better in practice than FF on average, but worst similar.
- Needs searching bins by leftover.
Next Fit (NF): Keep only current bin open; if item doesn't fit current, close it and open new bin (don't look back).
- Simplest , but worst (factor 2, worse than FF/BF). Example: items → NF uses 4 bins vs OPT2? Actually NF: bin1:0.5+0.5 fits →2 items per bin →2 bins optimal; worst case alternating 0.6,0.4 etc shows gap.
Sorted variants: First Fit Decreasing (FFD), Best Fit Decreasing (BFD) sort items descending first → improves to (~1.22) for FFD/BFD, best among simple heuristics.
Example , items 6,6,5,5,4,4,4:
- NF: Bin1 6 → next6 no fit → Bin2 6, 5 no→Bin3 5,4 fits→5+4=9, next4 no→Bin4 4,4→8 → total4 bins
- FF: Bin1 6+4=10, Bin2 6+4=10, Bin3 5+5=10, Bin4 4→4 bins optimal =4
- BF similar 4.
Optimal is NP-hard; heuristics give fast near-optimal packing used in memory allocation, cutting stock, scheduling.
Q9. Write the short note on the following: (a) Cook's theorm (b) Randomized algorithms (c) Bin Packing202314m
Module 5: Advanced Topics
View this question on its own page →Write the short note on the following:
(a) Cook's theorm
(b) Randomized algorithms
(c) Bin PackingWorked SolutionShort Notes
(a) Cook's Theorem (see Q86/Q72)
SAT is first NP-complete problem (1971 Cook-Levin). Every reduces to SAT via tableau encoding of nondet TM computation into poly-size CNF formula with variables for tape/head/state over time steps . SAT∈NP via assignment verifier. Consequence: ; Karp reduced SAT to 21 other problems proving NP-completeness pervasive. Foundations of complexity and hardness proofs.
(b) Randomized Algorithms (see Q59/Q74)
Use random choices; types Las Vegas (always correct, random time, e.g., Randomized Quicksort expected ) vs Monte Carlo (bounded error, e.g., Miller-Rabin primality). Techniques: random sampling, hashing, random pivot. Expected time analysis via linearity of expectation. Power: avoid worst-case inputs, simple, often faster average. Derandomization open.
(c) Bin Packing (see Q99)
Items sizes , bins capacity1, minimize bins — NP-hard (reduction from Partition). Heuristics: Next Fit (factor2, ), First Fit & Best Fit (1.7 approx, ), First Fit Decreasing / Best Fit Decreasing sorted (11/9≈1.22 approx, best simple). Applications: cutting stock, memory allocation, scheduling. No PTAS with ratio <3/2 unless ; but asymptotic PTAS exists.
Q9a. Answer the following: (i) Describe randomized algorithms. (ii) Write the algorithm for randomized quick sort. (iii) Give the time complexity of randomized quick sort.20247m
Module 5: Advanced Topics
View this question on its own page →Answer the following:
(i) Describe randomized algorithms.
(ii) Write the algorithm for randomized quick sort.
(iii) Give the time complexity of randomized quick sort.Worked SolutionRandomized Algorithms & Randomized Quicksort
(i) Randomized Algorithms (as in Q59)
Algorithms using random bits to make decisions; behavior probabilistic. Las Vegas always correct, running time random (e.g., Randomized QuickSort, Skip List). Monte Carlo may be incorrect with bounded probability (e.g., Miller-Rabin). Usage: avoid adversary, simple, expected guarantees.
(ii) Randomized Quicksort Algorithm
RandomizedQuicksort(A, low, high): if low < high: p = RandomizedPartition(A, low, high) // random pivot RandomizedQuicksort(A, low, p-1) RandomizedQuicksort(A, p+1, high) RandomizedPartition(A, low, high): i = Random(low, high) // uniform swap A[i], A[high] return Partition(A, low, high) // Lomuto/Hoare as in Q14Alternative: pick random pivot internally without swap.
(iii) Time Complexity
- Worst-case still but probability extremely low (requires always bad pivot). No adversary can force it (random pivot independent of input order).
- Expected (over random choices) for any input. Proof: expected partition splits balanced on average; linearity of expectation over comparisons → solves to .
- Best .
- Space expected stack depth.
Randomization converts worst-case on sorted input (deterministic pivot last) into expected universally.
Q9a. Write a short note on: Heuristics characteristics and their application domains.20257m
Module 5: Advanced Topics
View this question on its own page →Write a short note on:
Heuristics characteristics and their application domains.
Worked SolutionHeuristics — Characteristics & Application Domains
What is a Heuristic?
Problem-solving technique using practical, rule-of-thumb, or educated-guess approach that is not guaranteed optimal but gives good enough quickly for hard (often NP-hard) problems. Heuristics trade optimality for speed/feasibility.
Characteristics
- No guarantee of optimal or bounded approximation (vs approximation algorithm has ratio bound; heuristic may be unbounded).
- Problem-specific knowledge embedded (e.g., nearest neighbor for TSP).
- Fast, simple — polytime, often or , usable where exact exponential infeasible.
- Empirically good — works well on typical instances despite worst pathological cases.
- No need to prove ratio — evaluated by experiments/benchmarks.
- Can be combined with metaheuristics (simulated annealing, genetic algorithms, tabu search) for improvement.
vs Approximation Algorithms
Heuristic Approximation Algorithm No proven bound Proven ratio guarantee Often faster/simpler May be more complex (LP rounding) Used when bound not needed Used when guarantee required Application Domains
- Combinatorial Optimization: TSP (nearest neighbor, 2-opt), Knapsack (greedy ratio), Bin Packing (FF/BF), Graph Coloring (greedy ordering), Vertex Cover (max degree greedy), Scheduling (list scheduling LPT).
- AI Search: A* heuristic (admissible Manhattan distance for 8-puzzle, Euclidean for pathfinding) — guides search.
- Routing & Networks: Vehicle routing, network design.
- Resource Allocation: Task scheduling, load balancing, memory allocation.
- Machine Learning: Feature selection heuristics, decision tree splits (information gain).
Examples: Bin Packing First Fit, TSP nearest neighbor tour, Sudoku backtracking with MRV heuristic.
Q9b. Write short notes on the following: (i) Approximation algorithms. (ii) Why are they important in the context of NP-hard optimization problems? (iii) Describe how approximation algorithms can be applied to the Vertex Cover problem.20247m
Module 5: Advanced Topics
View this question on its own page →Write short notes on the following:
(i) Approximation algorithms.
(ii) Why are they important in the context of NP-hard optimization problems?
(iii) Describe how approximation algorithms can be applied to the Vertex Cover problem.Worked SolutionApproximation Algorithms — Importance & Vertex Cover Application
(i) Approximation Algorithms
Polytime algorithms that produce feasible solution with proven distance from optimum. For minimization minimization: ; for maximization ; approximation ratio (performance guarantee). Contrasts with heuristics (no guarantee).
Examples: Metric TSP 2-approx (MST doubling), Christofides 1.5, Set Cover , Knapsack FPTAS.
(ii) Importance for NP-Hard Optimization
- Exact polytime impossible unless → need alternative for large instances.
- Provides usable solution with confidence bound; helps decide tradeoff speed vs quality.
- Underpins theoretical classification: APX, PTAS, FPTAS hierarchy shows which problems approximable arbitrarily well.
- Guides practice: if problem hard to approximate (e.g., Clique within hard), don't waste effort seeking good approx; use heuristic/exponential exact for moderate .
Without approximation, only brute exact feasible for tiny ; approximation scales to thousands.
(iii) Applied to Vertex Cover
Minimum Vertex Cover: min vertices covering all edges — NP-hard (reduction from 3-SAT).
2-Approximation (as in Q84/Q97):
C=∅; E' =E while E'≠∅: pick any (u,v)∈E'; C∪={u,v}; remove all edges incident to u or vMatching picked disjoint → (need one per edge) → → ratio2.
Example: Path . Pick → , remove edges → remaining → pick → size4 vs OPT2 () → ratio2 tight for path? star gives ratio2 worst.
Hardness: Assuming Unique Games, no polytime approx for vertex cover — so this simple 2-approx is essentially best possible.
Thus approximation bridges intractability and practical need.