Algorithm Design Techniques MCQs for NSCT
Algorithm design techniques are the general strategies for building algorithms: divide and conquer, greedy, dynamic programming (DP) and backtracking. Exam questions ask you to recognise which strategy fits a problem, apply it to small numbers and spot where a strategy fails. Algorithm Design Techniques is topic 9 of the Data Structures & Algorithms area, which carries 10% of the NSCT according to HEC's Areas of Competencies. In 2026 candidates averaged 40.2% in DSA, per the HEC NSCT report and APP.
| Technique | Core idea | Classic examples |
|---|---|---|
| Divide and conquer | Split into independent subproblems, solve, combine | Merge sort, quicksort, binary search, Strassen |
| Greedy | Take the locally best choice, never undo it | Huffman, Kruskal, Prim, Dijkstra, activity selection |
| Dynamic programming | Solve overlapping subproblems once, store answers | 0/1 knapsack, LCS, edit distance, Floyd-Warshall |
| Backtracking | Build partial solutions, abandon dead ends | N-Queens, Sudoku, subset sum |
Divide and conquer
Divide and conquer has three steps: divide the problem, conquer each part recursively, and combine the results. Merge sort does its work in the combine step (merging), while quicksort does its work in the divide step (partitioning).
Running times come from recurrences, usually solved with the master theorem for T(n) = aT(n/b) + f(n). Merge sort is T(n) = 2T(n/2) + n = Θ(n log n). Binary search is T(n) = T(n/2) + 1 = Θ(log n); some textbooks call that case "decrease and conquer". Exam angle: the subproblems are independent, so memoisation gives no speed-up here.
Greedy
A greedy algorithm commits to the best-looking choice at each step. It is correct only when the problem has the greedy-choice property (some optimal solution starts with the greedy choice) and optimal substructure. Correctness is usually proved with an exchange argument.
Activity selection is the standard success: sort by finish time and take each activity that starts after the last one chosen. For (1,3), (2,5), (4,6), (6,8), (5,9) this picks (1,3), (4,6), (6,8), which is 3 activities. Coin change is the standard failure: with coins 1, 5, 6, 9 and amount 11, greedy takes 9 + 1 + 1 (3 coins), but 5 + 6 needs only 2. Exam angle: greedy by value/weight ratio is optimal for fractional knapsack but not for 0/1 knapsack.
Dynamic programming
DP applies when a problem has optimal substructure and overlapping subproblems. Each subproblem is solved once and stored, either top-down with memoisation or bottom-up with tabulation.
Naive recursive Fibonacci makes 9 calls for fib(4) and grows exponentially; a table from fib(0) up to fib(n) needs n − 1 additions. For 0/1 knapsack with capacity 5 and items (value 3, weight 2), (4, 3), (5, 4), the table gives 7 (the first two items). The O(nW) knapsack DP is pseudo-polynomial: it is fast only when the capacity W is small. Exam angle: if the question asks for a count or a minimum over many choices, and the same sub-question recurs, think DP. The dynamic programming page has full table walkthroughs.
Backtracking
Backtracking explores a state-space tree depth first. It extends a partial solution one choice at a time and undoes the last choice as soon as a constraint fails. The 4-Queens problem has exactly 2 solutions and 6-Queens has 4; pruning means far fewer than the n^n raw placements are ever tried.
Branch and bound extends the idea to optimisation problems. It keeps the best solution found so far and prunes any branch whose bound cannot beat it. Exam angle: backtracking prunes on constraints, branch and bound also prunes on cost, and both stay exponential in the worst case.
Common traps
- Calling Dijkstra or Prim dynamic programming. Most textbooks, including CLRS, classify them as greedy.
- Assuming greedy works for any coin system. It works for 1, 5, 10, 25, but fails for 1, 3, 4 and for 1, 5, 6, 9.
- Using the fractional knapsack answer for a 0/1 knapsack question.
- Adding memoisation to divide and conquer and expecting a speed-up when no subproblem repeats.
- Reading the master theorem's a and b the wrong way round: a is the number of subproblems, n/b is their size.
Worked examples
Understanding. Kruskal's algorithm sorts edges by weight and keeps every edge that does not close a cycle. Which design technique is it? Answer: greedy. It takes the cheapest safe edge each time and never removes one, and the cut property proves that choice is always safe.
Application. What is the length of the longest common subsequence of ABCD and ACBD? Answer: 3. ABD and ACD both work. The LCS table fills cell (i, j) with diagonal + 1 on a match, otherwise the larger of the cells above and to the left, and the last cell is 3.
Analysis. A recursive solution to a problem is correct but very slow, and a trace shows the same arguments recurring thousands of times. What is the best fix? Answer: convert it to dynamic programming. Repeated arguments mean overlapping subproblems, so caching each result (memoisation) or filling a table bottom-up removes the exponential repeated work without changing the logic.
Practise
The quiz below has 100 Algorithm Design Techniques questions, which you can filter by tier and difficulty.
Practise: 100 questions
FAQs
What is the difference between divide and conquer and dynamic programming?
Both break a problem into subproblems. In divide and conquer the subproblems are independent, as in the two halves of merge sort, so each is solved once anyway. In dynamic programming the subproblems overlap, so storing their answers avoids repeated work.
How do I know if a greedy algorithm will work?
Try to prove the greedy-choice property with an exchange argument, or hunt for a small counterexample. If a few minutes with small numbers produces a case where greedy loses, as with coins 1, 3, 4 and amount 6, use dynamic programming instead.
Is backtracking the same as brute force?
No. Brute force generates every complete candidate and checks it. Backtracking checks constraints on partial candidates and abandons a whole branch as soon as it fails, so it usually explores far fewer states, although its worst case is still exponential.
Which design technique is binary search?
Most textbooks list it under divide and conquer. Some, such as Levitin, call it decrease and conquer, because it solves only one subproblem of half the size. Either label is accepted if the reasoning is right.
Next step
Continue with Advanced Data Structures MCQs, go back to the DSA hub, or try a timed NSCT mock test.