Design and Analysis of Algorithms

106502
Back to Design and Analysis of Algorithms

Module 5: Advanced Topics

  1. 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

    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) 1

    View this question on its own page →
    Worked Solution

    Answer: (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 v
      

      Any optimal cover must include at least one endpoint of each picked edge, and picked edges are disjoint. So ∣C∣≤2⋅∣OPT∣|C| ≤ 2·|OPT|.

    • Ratio 2 is tight; a simple maximal-matching algorithm achieves it. No polynomial algorithm can achieve (2−ϵ)(2-\epsilon) unless P=NPP=NP (inapproximability). The naive greedy "pick highest-degree vertex" can be Θ(log⁡n)\Theta(\log n) bad, not 2.

    Correct choice: (i) 2

  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

    Randomized algorithms make use of:
    (i) Deterministic input
    (ii) Random choices during execution
    (iii) Recursive backtracking
    (iv) Fixed input-output pairs

    View this question on its own page →
    Worked Solution

    Answer: (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 O(nlog⁡n)O(n \log n)) or achieve simplicity/probabilistic guarantees.

    Correct choice: (ii)

  3. Q7a. Explain the approximation algorithm for the travelling salesman problem.20257m

    Module 5: Advanced Topics

    Explain the approximation algorithm for the travelling salesman problem.

    View this question on its own page →
    Worked Solution

    Approximation Algorithm for TSP (Metric TSP — 2-Approximation)

    For general TSP (arbitrary distances) no polytime approximation exists unless P=NPP=NP (Hamiltonian cycle reduces). For Metric TSP (complete graph satisfying triangle inequality c(u,w)≤c(u,v)+c(v,w)c(u,w) ≤ c(u,v)+c(v,w)) a constant-factor approximation exists.

    2-Approximation via MST ( MST-doubling )

    Approx-TSP(G, c):
      T = MST(G)  // via Prim/Kruskal O(Elog⁡V)O(E\log V)
      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 → c(T)≤c(OPT)c(T) ≤ c(OPT). Full walk of T traverses each edge twice → c(W)=2c(T)≤2c(OPT)c(W)=2c(T) ≤2c(OPT). Shortcutting via triangle inequality can only decrease cost → c(H)≤c(W)≤2c(OPT)c(H) ≤c(W) ≤2c(OPT) → 2-approximation. Time O(V2)O(V^2) or O(Elog⁡V)O(E\log V).

    Christofides 1.5-Approximation (better)

    1. Find MST TT.
    2. Find minimum weight perfect matching MM on vertices of TT with odd degree (even number, via Blossom O(V3)O(V^3)).
    3. Combine T∪MT∪M (Eulerian multigraph, all vertices even degree).
    4. Find Euler tour, shortcut to Hamiltonian cycle.
      Ratio: c(T)≤OPTc(T)≤OPT, c(M)≤OPT/2c(M)≤OPT/2 → c(H)≤1.5OPTc(H)≤1.5 OPT.

    Heuristic without guarantee: Nearest Neighbor, 2-opt local search.

  4. Q7b. Discuss the steps to find approximate solutions to NP-Hard optimization problems using approximation algorithms with an example.20257m

    Module 5: Advanced Topics

    Discuss the steps to find approximate solutions to NP-Hard optimization problems using approximation algorithms with an example.

    View this question on its own page →
    Worked Solution

    Approximation 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

    1. Formulate optimization: Min or Max objective (e.g., min vertex cover size, min tour length).
    2. Check complexity: Prove NP-hard (reduction from known NP-hard). → motivates approximation.
    3. Design polytime heuristic: Often greedy, DP relaxation, LP rounding, MST/matching, local search.
    4. Prove approximation ratio ρ\rho:
      • For minimization: ALGOPT≤ρ\frac{ALG}{OPT} \le \rho
      • For maximization: OPTALG≤ρ\frac{OPT}{ALG} \le \rho
        Show bound via lower bound on OPT (e.g., LP optimum ≤ OPT, MST ≤ TSP OPT) and upper bound on ALG.
    5. Analyze time: Must be polytime (e.g., O(nlog⁡n)O(n\log n), O(n3)O(n^3)).
    6. Tighten: Improve ratio or show hardness of better approximation (inapproximability).

    Example: Minimum Vertex Cover — 2-Approximation

    Input graph G(V,E)G(V,E), 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 C
    

    Proof of ratio 2: Let MM be set of edges picked (matching, disjoint). Any vertex cover must include ≥1 endpoint per edge in MM → OPT≥∣M∣OPT ≥ |M|. Algorithm includes both endpoints → ∣C∣=2∣M∣≤2⋅OPT|C|=2|M| ≤2·OPT.

    Example graph: Triangle a−b,b−c,c−aa-b, b-c, c-a. MM picks (a,b)(a,b) → C=a,bC={a,b} size2, OPT=2 (any 2 cover) ratio1. Star center+leaves: picks center-leaf → CC size2 vs OPT1 → ratio2 tight.

    Time O(V+E)O(V+E).

    Other examples: Metric TSP 2-approx via MST (Q96), Knapsack FPTAS, Set Cover ln⁡n\ln n greedy.

    Importance: Provides usable solutions with guarantee where exact is infeasible.

  5. Q8b. Explain the Bin Packing Problem using heuristic techniques such as: * First Fit * Best Fit * Next Fit20257m

    Module 5: Advanced Topics

    Explain the Bin Packing Problem using heuristic techniques such as:

    • First Fit
    • Best Fit
    • Next Fit
    View this question on its own page →
    Worked Solution

    Bin Packing Problem & Heuristics

    Problem

    Given items sizes si∈(0,1]s_i ∈ (0,1] (bin capacity 1) or integer capacity CC, 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 O(nlog⁡n)O(n\log n) or O(n·#bins).
    • Approximation: FF≤1.7⋅OPT+1FF ≤ 1.7·OPT +1 (Johnson), uses at most ⌈1.7OPT⌉⌈1.7 OPT⌉ 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 O(n)O(n), but worst 2⋅OPT−12·OPT -1 (factor 2, worse than FF/BF). Example: items 0.5,0.5,0.5,0.50.5,0.5,0.5,0.5 → 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 11/9OPT+111/9 OPT +1 (~1.22) for FFD/BFD, best among simple heuristics.

    Example C=10C=10, 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.

  6. Q9. Write the short note on the following: (a) Cook's theorm (b) Randomized algorithms (c) Bin Packing202314m

    Module 5: Advanced Topics

    Write the short note on the following:
    (a) Cook's theorm
    (b) Randomized algorithms
    (c) Bin Packing

    View this question on its own page →
    Worked Solution

    Short Notes

    (a) Cook's Theorem (see Q86/Q72)

    SAT is first NP-complete problem (1971 Cook-Levin). Every L∈NPL∈NP reduces to SAT via tableau encoding of nondet TM computation into poly-size CNF formula φxφ_x with variables for tape/head/state over time steps p(n)p(n). SAT∈NP via assignment verifier. Consequence: P=NP⇔SAT∈PP=NP ⇔ SAT∈P; 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 O(nlog⁡n)O(n\log n)) 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 ∈(0,1]∈(0,1], bins capacity1, minimize bins — NP-hard (reduction from Partition). Heuristics: Next Fit (factor2, O(n)O(n)), First Fit & Best Fit (1.7 approx, O(nlog⁡n)O(n\log n)), 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 P=NPP=NP; but asymptotic PTAS exists.

  7. 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

    Answer the following:
    (i) Describe randomized algorithms.
    (ii) Write the algorithm for randomized quick sort.
    (iii) Give the time complexity of randomized quick sort.

    View this question on its own page →
    Worked Solution

    Randomized 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 Q14
    

    Alternative: pick random pivot internally without swap.

    (iii) Time Complexity

    • Worst-case still Θ(n2)Θ(n^2) but probability extremely low (requires always bad pivot). No adversary can force it (random pivot independent of input order).
    • Expected (over random choices) Θ(nlog⁡n)Θ(n \log n) for any input. Proof: expected partition splits balanced on average; linearity of expectation over comparisons → E[T(n)]=2/n∑kE[T(k)]+Θ(n)E[T(n)] = 2/n \sum_{k} E[T(k)] + Θ(n) solves to Θ(nlog⁡n)Θ(n\log n).
    • Best Θ(nlog⁡n)Θ(n\log n).
    • Space O(log⁡n)O(\log n) expected stack depth.

    Randomization converts worst-case O(n2)O(n^2) on sorted input (deterministic pivot last) into expected O(nlog⁡n)O(n\log n) universally.

  8. Q9a. Write a short note on: Heuristics characteristics and their application domains.20257m

    Module 5: Advanced Topics

    Write a short note on:

    Heuristics characteristics and their application domains.

    View this question on its own page →
    Worked Solution

    Heuristics — 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 O(nlog⁡n)O(n\log n) or O(n2)O(n^2), 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 h(n)h(n) (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.

  9. 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

    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.

    View this question on its own page →
    Worked Solution

    Approximation Algorithms — Importance & Vertex Cover Application

    (i) Approximation Algorithms

    Polytime algorithms that produce feasible solution with proven distance from optimum. For minimization minimization: ALG≤ρ⋅OPTALG ≤ ρ·OPT; for maximization OPT≤ρ⋅ALGOPT ≤ ρ·ALG; ρ≥1ρ≥1 approximation ratio (performance guarantee). Contrasts with heuristics (no guarantee).

    Examples: Metric TSP 2-approx (MST doubling), Christofides 1.5, Set Cover ln⁡n\ln n, Knapsack FPTAS.

    (ii) Importance for NP-Hard Optimization

    • Exact polytime impossible unless P=NPP=NP → 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 n1−εn^{1-ε} hard), don't waste effort seeking good approx; use heuristic/exponential exact for moderate nn.

    Without approximation, only brute O(2n)O(2^n) exact feasible for tiny nn; 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 v
    

    Matching MM picked disjoint → OPT≥∣M∣OPT ≥|M| (need one per edge) → ∣C∣=2∣M∣≤2OPT|C|=2|M| ≤2 OPT → ratio2.

    Example: Path a−b−c−da-b-c-d. Pick (a,b)(a,b) → C=a,bC={a,b}, remove edges ab,bcab,bc → remaining c−dc-d → pick (c,d)(c,d) → C=a,b,c,dC={a,b,c,d} size4 vs OPT2 (b,cb,c) → ratio2 tight for path? star gives ratio2 worst.

    Hardness: Assuming Unique Games, no polytime (2−ε)(2-ε) approx for vertex cover — so this simple 2-approx is essentially best possible.

    Thus approximation bridges intractability and practical need.