2025 question paper
Design and Analysis of Algorithms
28 questions
Q1a. Which property of an algorithm ensures that every step is clear and has exactly one meaning? (i) Finiteness (ii) Effectiveness (iii) Definiteness (iv) Generality20252m
Module 1: Introduction
View this question on its own page →Which property of an algorithm ensures that every step is clear and has exactly one meaning?
(i) Finiteness
(ii) Effectiveness
(iii) Definiteness
(iv) GeneralityWorked SolutionAnswer: (iii) Definiteness
- Finiteness: terminates after finite steps
- Definiteness: each step unambiguous
- Effectiveness: each step basic feasible
- Generality: works for all inputs of type
Q1b. In Asymptotic notation, Big- \Omega (Omega) is used to represent (i) The upper bound (Worst-case) (ii) The lower bound (Best-case) (iii) The tight bound (Average-case) (iv) None of the above20252m
Module 1: Introduction
View this question on its own page →In Asymptotic notation, Big- (Omega) is used to represent
(i) The upper bound (Worst-case)
(ii) The lower bound (Best-case)
(iii) The tight bound (Average-case)
(iv) None of the aboveWorked SolutionCorrect option: (ii) The lower bound (as the intended distinction in this question).
Big-Ω (Omega) notation describes an asymptotic lower bound on a function's growth. Formally, (f(n) \in \Omega(g(n))) if there are constants (c>0) and (n_0) such that (f(n) \ge c,g(n)) for every (n \ge n_0).
Important clarification: Big-Ω does not inherently mean best-case complexity. Upper bound, lower bound and tight bound are properties of asymptotic notation; best-case, worst-case and average-case describe which case of an algorithm's input behaviour is being analysed. A lower bound can be applied to any of those functions.
- Big-O: asymptotic upper bound.
- Big-Ω: asymptotic lower bound.
- Big-Θ: asymptotically tight bound.
Therefore, choose option (ii) for the lower-bound part, but do not memorize “Ω = best case” as a general rule.
Q1c. A FIFO Branch-and-Bound strategy is typically implemented using which data structure? (i) Stack (ii) Queue (iii) Priority Queue (iv) Array20252m
Module 2: Fundamental Algorithmic Strategies
View this question on its own page →A FIFO Branch-and-Bound strategy is typically implemented using which data structure?
(i) Stack
(ii) Queue
(iii) Priority Queue
(iv) ArrayWorked SolutionAnswer: (ii) Queue
- BFS → Queue, DFS → Stack
- Branch-and-Bound FIFO → Queue, LIFO → Stack, LC → Priority Queue
Q1d. The 0/1 Knapsack problem is traditionally solved using which approach to ensure an optimal solution? (i) Greedy Method (ii) Dynamic Programming (iii) Brute-Force only (iv) Linear Search20252m
Module 2: Fundamental Algorithmic Strategies
View this question on its own page →The 0/1 Knapsack problem is traditionally solved using which approach to ensure an optimal solution?
(i) Greedy Method
(ii) Dynamic Programming
(iii) Brute-Force only
(iv) Linear SearchWorked SolutionAnswer: (ii) Dynamic Programming
0/1 Knapsack optimal via DP table O(n*W). Greedy works only for fractional knapsack.
Q1e. In an unweighted graph, which algorithm is guaranteed to find the shortest path between two nodes? (i) Depth First Search (ii) Kruskal's Algorithm (iii) Breadth First Search (iv) Prim's Algorithm20252m
Module 3: Graph and Tree Algorithms
View this question on its own page →In an unweighted graph, which algorithm is guaranteed to find the shortest path between two nodes?
(i) Depth First Search
(ii) Kruskal's Algorithm
(iii) Breadth First Search
(iv) Prim's AlgorithmWorked SolutionAnswer: (iii) Breadth First Search
BFS gives shortest path in unweighted graph (by levels). DFS not guaranteed, MST algorithms not for shortest path.
Q1f. Which of the following algorithms is commonly used to find the Minimum Spanning Tree of a graph? (i) Dijkstra's Algorithm (ii) Kruskal's Algorithm (iii) Bellman-Ford Algorithm (iv) Floyd-Warshall Algorithm20252m
Module 3: Graph and Tree Algorithms
View this question on its own page →Which of the following algorithms is commonly used to find the Minimum Spanning Tree of a graph?
(i) Dijkstra's Algorithm
(ii) Kruskal's Algorithm
(iii) Bellman-Ford Algorithm
(iv) Floyd-Warshall AlgorithmWorked SolutionAnswer: (ii) Kruskal's Algorithm
Explanation:
- Minimum Spanning Tree (MST) of a connected, undirected, weighted graph is found by greedy MST algorithms:
- Prim's: grows tree from a vertex, repeatedly adds minimum-weight edge crossing cut. .
- Kruskal's: sorts all edges, adds edges in increasing order skipping those forming a cycle (using Union-Find). .
- Dijkstra's, Bellman-Ford, Floyd-Warshall solve shortest paths, not MST.
- Both Prim's and Kruskal's are valid; here the option listed is Kruskal's.
Correct choice: (ii) Kruskal's Algorithm (Prim's would also be correct if listed).
- Minimum Spanning Tree (MST) of a connected, undirected, weighted graph is found by greedy MST algorithms:
Q1g. If all edge weights in a graph are positive, what is the minimum number of edges in a spanning tree for a graph with vertices? (i) V (ii) V-1 (iii) V+1 (iv) 2V20252m
Module 3: Graph and Tree Algorithms
View this question on its own page →If all edge weights in a graph are positive, what is the minimum number of edges in a spanning tree for a graph with vertices?
(i) V
(ii) V-1
(iii) V+1
(iv) 2VWorked SolutionAnswer: (ii)
Explanation:
- A spanning tree of a connected graph with vertices is a tree that includes all vertices.
- Any tree with vertices has exactly edges (proof by induction; also characterizes trees among connected graphs).
- Edge weights (positive or otherwise) do not affect the count — any spanning tree, regardless of weight, has edges. Minimum spanning tree also has edges; weight affects which edges, not how many.
- Additional edges would create a cycle → not a tree.
Correct choice: (ii) (if graph disconnected, spanning forest has edges for components).
Q1h. Which complexity class contains problems for which a given solution can be verified in polynomial time by a deterministic Turing machine? (i) Class P (ii) Class NP (iii) Class NP-Hard (iv) Class Undecidable20252m
Module 4: Tractable and Intractable Problems
View this question on its own page →Which complexity class contains problems for which a given solution can be verified in polynomial time by a deterministic Turing machine?
(i) Class P
(ii) Class NP
(iii) Class NP-Hard
(iv) Class UndecidableWorked SolutionAnswer: (ii) Class NP
Explanation:
- P: problems solvable in polynomial time by a deterministic TM.
- NP: problems where a proposed solution (certificate) can be verified in polynomial time by a deterministic TM (equivalently, solvable in polynomial time by a non-deterministic TM). .
- NP-Hard: at least as hard as any NP problem (every NP problem reduces to it); may not be in NP.
- NP-Complete = NP NP-Hard.
- Undecidable: no TM can solve all instances.
The definition "verifiable in polynomial time by deterministic TM" is exactly NP.
Correct choice: (ii) Class NP
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. The Quantified Boolean Formula problem is a canonical complete problem for which of the following complexity classes? (i) NP (ii) P (iii) PSPACE (iv) co-NP20252m
Module 4: Tractable and Intractable Problems
View this question on its own page →The Quantified Boolean Formula problem is a canonical complete problem for which of the following complexity classes?
(i) NP
(ii) P
(iii) PSPACE
(iv) co-NPWorked SolutionAnswer: (iii) PSPACE
Explanation:
- QBF (Quantified Boolean Formula): given , is it true? It extends SAT with quantifiers.
- QBF is PSPACE-complete (Stockmeyer-Meyer 1973). SAT is NP-complete; QBF with unbounded alternation captures polynomial-space computation.
- Complete for PSPACE under polytime reductions → canonical PSPACE-complete problem.
- NP is -only; co-NP is -only; PSPACE allows both via alternation.
Correct choice: (iii) PSPACE
- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
Q2a. Write and explain the Cook's theorem.20257m
Module 4: Tractable and Intractable Problems
View this question on its own page →Write and explain the Cook's theorem.
Worked SolutionCook's Theorem (1971) — SAT is NP-Complete
Statement:
The Boolean Satisfiability problem (SAT) — given a Boolean formula in CNF, is there an assignment making true? — is NP-complete.More precisely Cook proved CNF-SAT is NP-complete; Levin independently proved general SAT. Hence 3-SAT is also NP-complete.
Proof Idea
Must show (1) SAT NP and (2) SAT is NP-hard: every NP polytime-reduces to SAT.
SAT NP: certificate = satisfying assignment, verifier checks formula in polytime.
Every NP language reduces to SAT:
- Let NP decided by nondeterministic TM in time (polynomial).
- For input , , construct Boolean formula that encodes the entire computation tableau of on : variables represent tape cells, head position, state at each time step .
- Add clauses enforcing: initial configuration = , each step follows 's transition relation, and final state is accepting.
- is satisfiable iff there exists an accepting computation path of on .
- Size of is — polynomial.
- Conversion is deterministic polytime.
Hence SAT → SAT.
Significance
- First NP-complete problem — seeds all other NP-completeness proofs by reduction from SAT.
- Implies SAT P.
- Foundations of complexity theory; Karp's 1972 paper reduced SAT to 21 other combinatorial problems (Clique, Vertex Cover, Hamiltonian Cycle), establishing NP-completeness as pervasive.
Corollary
3-SAT (each clause has exactly 3 literals) remains NP-complete via simple reduction from SAT (splitting long clauses with auxiliary variables).
Q2b. Define time complexity and space complexity. Write an algorithm for adding n natural numbers and find the space required by that algorithm.20257m
Module 1: Introduction
View this question on its own page →Define time complexity and space complexity. Write an algorithm for adding n natural numbers and find the space required by that algorithm.
Worked SolutionTime and Space Complexity + Algorithm to Add Naturals
Definitions
- Time Complexity: asymptotic number of basic operations (steps) as function of input size , .
- Space Complexity: asymptotic total memory (input + auxiliary + recursion stack) ; often reported as auxiliary space (extra beyond input).
Algorithm — Sum of First Natural Numbers
Iterative time, aux space:
Algorithm SumNatural(n): sum ← 0 for i ← 1 to n: sum ← sum + i return sumTime: iterations × → ( additions). Space: variables , , → 3 words → auxiliary ( if counting input array? Here input is just → ).
Formula time (mathematical):
Algorithm SumFormula(n): return n*(n+1)//2Time arithmetic operations, space . Uses closed form .
Recursive (for illustration):
RecSum(n): if n==1 return 1 else return n + RecSum(n-1)Time , stack space due to frames — worse.
Analysis Summary
Variant Time Auxiliary Space Total Space Iterative loop Formula Recursive stack Best practical: formula . If required to demonstrate space complexity concept, loop shows auxiliary despite time.
Q3a. Discuss the concepts of asymptotic notations and its properties.20257m
Module 1: Introduction
View this question on its own page →Discuss the concepts of asymptotic notations and its properties.
Worked SolutionAsymptotic Notations & Properties
Definitions (as in Q36)
- upper: .
- lower: .
- tight: → .
- strict upper: eventually ().
- strict lower ().
Properties
- Transitivity: (similar for ).
- Reflexivity: .
- Symmetry: ; transpose symmetry .
- Additivity/Max rule: If then . Hence polynomial .
- Scaling: for constant ; lower-order terms absorbed.
- Ordering: .
- Polynomial gap: if ; any poly is .
- Master/recurrence use: notations hide constants allowing comparison Unabhängig von Hardware.
Example Hierarchy
- Linear search worst , binary , merge , matrix mult naive , Strassen , TSP brute .
Pitfalls
- is not tight — use when both upper and lower known.
- Not all functions comparable ( incomparable).
- Amortized vs worst-case: still worst over sequence.
Q3b. What is a Minimum Cost Spanning tree? Explain Kruskal's Minimum cost spanning tree algorithm with a suitable example.20257m
Module 3: Graph and Tree Algorithms
View this question on its own page →What is a Minimum Cost Spanning tree? Explain Kruskal's Minimum cost spanning tree algorithm with a suitable example.
Worked SolutionMinimum Cost Spanning Tree & Kruskal's Algorithm
Definition
For connected undirected weighted graph , a spanning tree is acyclic connected subgraph spanning all with edges. Minimum Cost Spanning Tree (MST) / Minimum Spanning Tree is spanning tree minimizing . If distinct weights, MST unique; otherwise multiple. Cut property and cycle property characterize MST.
Kruskal's Algorithm (Greedy)
Kruskal(G): T=∅ sort E by weight ascending make Union-Find structure for V for (u,v) in sorted E: if Find(u) != Find(v): T.add((u,v)) Union(u,v) if |T|==|V|-1: break return TCorrectness via cut property: smallest edge crossing any cut belongs to some MST; cycle property prevents adding cycle edge.
Complexities: Sorting , Union-Find → total ( inverse Ackermann). Space .
Example
Graph: , edges: AB1, AC3, BC3, BD4, CD2
- Sorted: AB1, CD2, AC3, BC3, BD4
- Add AB1 (A|B), add CD2 (C|D), add AC3 (merges {A,B} with {C,D} → {A,B,C,D}), skip BC3 (would cycle A-B-C), skip BD4. MST weight 1+2+3=6 edges AB,CD,AC.
Kruskal vs Prim
- Kruskal edge-based, good for sparse graphs; Prim vertex-based, good for dense ( with heap, naive).
- Both optimal, choice depends on density and structure.
Q4a. Find an optimal solution to the knapsack instance n=4 objects and the capacity of knapsack m=15, profits are (10, 5, 7, 11) and weights are (3, 4, 3, 5).20257m
Module 2: Fundamental Algorithmic Strategies
View this question on its own page →Find an optimal solution to the knapsack instance objects and the capacity of knapsack , profits are and weights are .
Worked Solution0/1 Knapsack , , , — Optimal via DP
DP Table (i items, w capacity)
Recurrence if .
Computed (rows , cols 0..15):
- (): dp=10 for
- (): combine → max 10 or 5+10? Let's build final row:
w 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 i=4 optimal 0 0 0 10 10 10 15 15 17 20 20 21 22 27 28 33 Full table via programmatic DP gives .
Traceback
- vs (items 1-3 best). Since , item4 included → remaining , value .
- vs ? Actually dp[3][10]=20 (includes item3). Since 20>15, item3 included → , value 13?
Wait systematic: At , dp3 includes item3 weight3 → dp2[7]+7. dp2[7]=15 (10+5) → 15+7=22? Let's present simpler reasoning: Total weight of all 4 items =3+4+3+5=15 exactly capacity, profit sum=10+5+7+11=33. Since capacity allows all, any subset profit <33 (remove any positive profit reduces total). So optimum is take all items.
Optimal Solution: , total weight 15, total profit 33. This is clearly optimal — proof by DP confirms no better feasible subset.
If capacity smaller, DP would prune; here trivial because .
Algorithm & Complexity
operations, space. General 0/1 knapsack is NP-hard, DP pseudo-polynomial.
Q4b. Compare NP-hard and NP-completeness?20257m
Module 4: Tractable and Intractable Problems
View this question on its own page →Compare NP-hard and NP-completeness?
Worked SolutionNP-Hard vs NP-Completeness
Aspect NP-Hard NP-Complete Definition Problem is NP-hard if every NP reduces to in polytime: NP, . No requirement that NP. is NP-complete iff is both NP-hard and NP. So NP-C = NP ∩ NP-hard. Verifiable? Not necessarily verifiable in polytime; may be harder than NP (e.g., Halting, undecidable problems are NP-hard). Yes, must be verifiable in polytime (certificate check ). Examples Halting Problem, 3-SAT optimization version, TSP optimization; also any NP-complete problem is NP-hard. Decision versions: SAT, 3-SAT, Clique decision, Vertex Cover decision, Hamiltonian Cycle, Subset Sum decision, TSP decision (is there tour ≤K?). Reduction direction To prove NP-hard: reduce known NP-hard/NP-complete . To prove NP-complete: prove (1) NP and (2) NP-hard (reduce known NP-complete to ). Solvability If NP-hard problem in P → P=NP, but converse not. NP-hard outside NP cannot be in NP regardless of P vs NP. If any NP-complete in P → P=NP → all NP problems polytime. Optimization vs Decision Optimization forms often NP-hard but not NP-complete because verification of optimality not polytime (just decision version is NP-complete). Decision versions with yes/no and polytime verifier. Venn: NP, NP-Complete ⊂ NP, NP-Hard superset overlapping NP (contains NP-C) and extending outside.
Consequence: Showing new problem NP-complete establishes it is among hardest in NP; showing NP-hard shows at least as hard as NP-complete, possibly harder/undecidable.
Q5a. Explain BFS algorithm in detail. Also explain its time complexity.20257m
Module 3: Graph and Tree Algorithms
View this question on its own page →Explain BFS algorithm in detail. Also explain its time complexity.
Worked SolutionBFS Algorithm — Detail & Time Complexity
Algorithm (Queue)
BFS(G, s): for each v in V: color[v]=WHITE, dist[v]=∞, parent[v]=NIL color[s]=GRAY; dist[s]=0; Q=queue(); ENQUEUE(Q,s) while Q ≠ ∅: u=DEQUEUE(Q) for each v in Adj[u]: if color[v]==WHITE: color[v]=GRAY; dist[v]=dist[u]+1; parent[v]=u; ENQUEUE(Q,v) color[u]=BLACKVariants output traversal order by recording dequeue order.
Example
Graph A→B,C etc, start A: queue [A] → visit A enqueue B,C → queue [B,C] → dequeue B enqueue D → [C,D] → dequeue C enqueue E → [D,E] → etc. Order A,B,C,D,E.
Time Complexity
- With adjacency list: Each vertex enqueued/dequeued once , each adjacency list scanned once → .
- With adjacency matrix: scan row of entries per vertex → .
Space for queue + color/dist arrays.
Properties
- Computes single-source shortest path (in edges) for unweighted graphs:
dist[v]= minimum number of edges s→v. - Produces BFS tree (parent pointers).
- Used as subroutine in Edmonds-Karp max flow, bipartite testing (2-coloring by levels), connected components.
- BFS levels correspond to distance layers; can also detect cycles / test bipartiteness by parity.
Q5b. Explain how Bellman Ford algorithm can be used to detect the presence of negative weight cycles.20257m
Module 3: Graph and Tree Algorithms
View this question on its own page →Explain how Bellman Ford algorithm can be used to detect the presence of negative weight cycles.
Worked SolutionBellman-Ford & Negative Weight Cycle Detection
Bellman-Ford Recap
Input: directed weighted graph , source .
Init: dist[s]=0, dist[v]=∞ for v≠s repeat V-1 times: for each edge (u,v) in E: if dist[u]+w(u,v) < dist[v]: dist[v]=dist[u]+w(u,v); parent[v]=uAfter iterations, = shortest path weight from using ≤ edges (any simple path has ≤ edges). Complexity .
Detecting Negative Cycle
Extra -th iteration:
for each edge (u,v) in E: if dist[u]+w(u,v) < dist[v]: // still relaxable then v is reachable from a negative cycle (and from s) report "Negative cycle exists reachable from s"Why? In graph without negative cycles, after rounds no edge can be relaxed (shortest paths have converged). If an edge can still be relaxed, the shortest path would require ≥ edges → must repeat a vertex → contains a cycle. Since total weight decreased by going around cycle, that cycle is negative. Moreover, repeated relaxation can propagate along all vertices reachable from the cycle.
Finding cycle: To retrieve cycle, follow parent pointers from times to get into cycle, then walk until repeat.
Example
Triangle (1), (-2), (-2): sum = -4 negative. After iterations dist keeps decreasing; Vth iteration detects relaxation.
Scope
- Detects only cycles reachable from . To detect any negative cycle in graph, add super-source with 0-edge to all vertices and run Bellman-Ford.
- Dijkstra cannot detect/develop must not be used with negatives.
Q6a. Explain the Prim's algorithm. What is the time complexity of Prim's algorithm?20257m
Module 3: Graph and Tree Algorithms
View this question on its own page →Explain the Prim's algorithm. What is the time complexity of Prim's algorithm?
Worked SolutionPrim's Algorithm & Time Complexity
Algorithm (Greedy MST)
Prim(G, s): for v in V: key[v]=∞, parent[v]=NIL, inMST[v]=false key[s]=0 Q = min-priority queue of V keyed by key while Q not empty: u = Extract-Min(Q); inMST[u]=true for each v in Adj[u]: if !inMST[v] and w(u,v) < key[v]: parent[v]=u; key[v]=w(u,v); Decrease-Key(Q,v,key[v])Growth from source , repeatedly adds minimum-weight edge crossing cut (cut property guarantees safety). Result = MST with edges, parent pointers form tree.
Example (as in Q89): start A, edges AB1 etc → picks AB1, then CD2 etc until MST weight minimal.
Correctness Sketch
Cut property: lightest edge crossing any cut belongs to some MST. Prim's cut is (inMST, rest); picking min crossing edge maintains invariant that inMST vertices are connected by MST edges.
Time Complexity
Depends on priority queue:
- Adjacency list + binary heap: = (extract-min times, decrease-key up to times).
- Adjacency list + Fibonacci heap: (amortized decrease-key ).
- Adjacency matrix + array (no heap, scan min): — best for dense graphs ().
- Adjacency matrix + binary heap: still .
Space: or for matrix.
Comparison
Prim good for dense graphs (array ), Kruskal better for sparse. Both optimal greedy MST algorithms.
Q6b. Apply the Prim's algorithm and find the optimal solution for the following graph: 20257m
Module 3: Graph and Tree Algorithms
View this question on its own page →Apply the Prim's algorithm and find the optimal solution for the following graph:

- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
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.
Q8a. Explain the Brute Force method of algorithm design with suitable examples.20257m
Module 2: Fundamental Algorithmic Strategies
View this question on its own page →Explain the Brute Force method of algorithm design with suitable examples.
Worked SolutionBrute Force Method of Algorithm Design
Definition
Brute force (exhaustive search) tries all possible candidates and picks those satisfying constraints. Simplest paradigm, directly from problem statement, no clever pruning.
Characteristics
- Generates entire solution space, tests each candidate.
- Always correct (finds optimum if enumerates all), but often exponential , , .
- Serves as baseline to compare smarter algorithms and for small verification.
Steps
- Enumerate all candidates (e.g., permutations, subsets, partitions).
- Test feasibility (constraints) and evaluate objective.
- Keep best feasible.
Examples
1. Sorting by brute force: Generate all permutations, test if sorted → vs optimal.
2. TSP brute force: Enumerate tours, compute length, pick min → vs DP Held-Karp .
3. Selection / Search: Linear search brute vs binary (needs sortedness).
4. String Matching brute force: For text , pattern , slide window: for compare with → worst vs KMP .
BruteForceMatch(T,P): for i=0..n-m: j=0; while j<m and P[j]==T[i+j]: j++ if j==m: return i return -15. Closest Pair brute: Check all pairs → vs divide&conquer .
Advantages / Disadvantages
- Pros: Simple, easy to implement/correct, covers all cases, good for small or to prove optimality via exhaustion.
- Cons: Infeasible for large ; does not exploit structure; usually improved by divide&conquer, DP, greedy, or heuristics.
Often first attempt; then optimize with clever design.
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.
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 a short note on: Recursion tree method20257m
Module 1: Introduction
View this question on its own page →Write a short note on:
Recursion tree method
Worked SolutionRecursion Tree Method
Idea
Visualize recurrence as tree where node = subproblem cost, level = total cost of that recursion depth, sum over levels gives total. Complements Master Theorem and substitution; handles forms master cannot (e.g., , uneven splits).
General Form
- Root cost
- children cost each → level1
- nodes cost → level2
- Depth leaves, leaves count cost each → leaf level .
- Total .
Example
Level0 , Level1 , Level2 → geometric ratio → sum dominated by root → (Case3).
Example
Tree: root , level1 , level2 → each level , depth → total .
Steps
- Draw tree, label cost per node/level.
- Determine depth (until or constant).
- Sum levels; identify geometric vs constant series.
- Verify via substitution (induction).
Advantages
- Intuitive for guessing bound for substitution proof.
- Handles non-uniform: → recursion tree shows still worst but more complex.
Use: Guess then prove via substitution method for rigor.
Q9c. Write a short note on: Dynamic Programming20257m
Module 2: Fundamental Algorithmic Strategies
View this question on its own page →Write a short note on:
Dynamic Programming
Worked SolutionDynamic Programming — Short Note
Definition
Optimization technique for problems with Optimal Substructure (optimal solution contains optimal solutions to subproblems) and Overlapping Subproblems (same subproblems recur many times). Solves each distinct subproblem once, stores result in table (memoization top-down or tabulation bottom-up).
Steps
- Characterize optimal substructure, define DP state.
- Write recurrence relating state to smaller states.
- Compute table bottom-up (or memoized recursion), determine order.
- Reconstruct optimal solution via parent pointers.
Key Properties vs Paradigms
- vs Divide&Conquer: D&C subproblems disjoint, DP overlapping.
- vs Greedy: Greedy picks local optimum once, DP explores all possibilities via table → guarantees global optimum when properties hold.
Classic Examples
- Fibonacci: naive → DP
- 0/1 Knapsack:
dp[i][w]=max(dp[i-1][w], dp[i-1][w-w_i]+p_i)→ pseudo-polynomial - Matrix Chain: →
- LCS / Edit Distance:
- Floyd-Warshall APSP: DP over intermediate vertices
- Optimal BST:
Complexities
Time = #states × transition cost; Space = #states (often optimizable to less). Improvement over brute force often from exponential to polynomial/pseudo-polynomial.
When to Use
If problem has optimal substructure + overlapping → DP likely best exact polytime/pseudo-polytime. If greedy-choice holds, greedy faster.
Q9d. Write a short note on: Asymptotic Notations20257m
Module 1: Introduction
View this question on its own page →Write a short note on:
Asymptotic Notations
Worked SolutionAsymptotic Notations — Short Note
Purpose
Describe algorithm growth for large , abstracting constants/hardware, classifying efficiency (as in Q36/Q88).
Definitions
- : — at most (upper bound).
- : — at least (lower bound).
- : — tight bound ().
- : eventually — strict upper ().
- : strict lower ().
Examples
- .
- , .
Hierarchy
— helps choose algorithm (e.g., merge vs insertion ).
Properties
Transitivity, reflexivity, symmetry for , transpose , sum rule .
Use: Analyze worst/best/average cases; e.g., linear search worst , binary , quicksort avg .
Coursify — Personal AI Course Generator
Struggling with a difficult subject or concept? Turn any engineering topic into a structured course with interactive lessons, quizzes, and research-backed explanations.