Algorithm Design Techniques MCQs for NSCT

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

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

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

Interactive quiz loading. The first 10 questions are shown below.

  1. What are the three steps of the divide-and-conquer technique?

    1. Select, check feasibility, add to solution
    2. Define states, fill a table, read the answer
    3. Divide, conquer (solve subproblems recursively), combine
    4. Choose, explore, un-choose
    Show answer

    Answer: C. Divide, conquer (solve subproblems recursively), combine

    Divide and conquer splits a problem into smaller independent subproblems, solves each recursively, then combines their answers. Merge sort is the standard example: split the array, sort both halves, then merge.

  2. Which description best fits a greedy algorithm?

    1. It makes the locally best choice at each step and never revisits it
    2. It tries every possible solution and keeps the best
    3. It stores answers to overlapping subproblems in a table
    4. It undoes choices when a constraint is violated
    Show answer

    Answer: A. It makes the locally best choice at each step and never revisits it

    A greedy algorithm commits to whatever looks best right now, such as the cheapest edge or the earliest finishing activity, without backtracking. It is correct only when the problem has the greedy-choice property and optimal substructure.

  3. Which two properties make a problem a good fit for dynamic programming?

    1. Greedy-choice property and sorted input
    2. Independent subproblems and a combine step
    3. A small search space and no constraints
    4. Optimal substructure and overlapping subproblems
    Show answer

    Answer: D. Optimal substructure and overlapping subproblems

    Optimal substructure means an optimal solution is built from optimal solutions to subproblems. Overlapping subproblems means the same subproblems recur, so storing each answer once saves exponential repeated work.

  4. What is the difference between memoisation and tabulation in dynamic programming?

    1. Memoisation is bottom-up; tabulation is top-down
    2. Memoisation is top-down recursion with a cache; tabulation fills a table bottom-up
    3. Only tabulation stores subproblem answers
    4. Memoisation is greedy; tabulation is divide and conquer
    Show answer

    Answer: B. Memoisation is top-down recursion with a cache; tabulation fills a table bottom-up

    Memoisation keeps the natural recursion and caches each result the first time it is computed, so only the subproblems actually needed get solved. Tabulation solves subproblems in dependency order with loops, which avoids recursion overhead. Both give the same asymptotic time.

  5. Which technique builds a solution one piece at a time and abandons a partial solution as soon as it breaks a constraint?

    1. Greedy
    2. Backtracking
    3. Divide and conquer
    4. Tabulation
    Show answer

    Answer: B. Backtracking

    Backtracking explores a state-space tree depth-first. When a partial candidate, such as two queens attacking each other, cannot lead to a valid solution, it prunes that branch and undoes the last choice.

  6. Which of these algorithms is a classic example of divide and conquer?

    1. Dijkstra's algorithm
    2. Merge sort
    3. Floyd-Warshall
    4. Prim's algorithm
    Show answer

    Answer: B. Merge sort

    Merge sort divides the array in half, sorts each half recursively and merges them. Dijkstra and Prim are greedy, and Floyd-Warshall is dynamic programming.

  7. Huffman coding builds an optimal prefix code by repeatedly merging the two least frequent symbols. Which design technique is this?

    1. Greedy
    2. Backtracking
    3. Divide and conquer
    4. Brute force
    Show answer

    Answer: A. Greedy

    At each step Huffman takes the locally best choice, the two smallest frequencies, and never revisits it. An exchange argument proves this gives a minimum total encoded length.

  8. Sorting items by value-to-weight ratio and taking the best first is optimal for which knapsack variant?

    1. Fractional knapsack only
    2. 0/1 knapsack only
    3. Both fractional and 0/1 knapsack
    4. Neither variant
    Show answer

    Answer: A. Fractional knapsack only

    In fractional knapsack you can take part of an item, so filling up with the highest ratio first is provably optimal. In 0/1 knapsack items are all-or-nothing, the ratio greedy can leave wasted capacity, and you need dynamic programming.

  9. How does branch and bound differ from plain backtracking?

    1. It never prunes any branch
    2. It explores the tree breadth-first only and stores no bounds
    3. It uses a bound on the best achievable objective to prune branches of an optimisation problem
    4. It only works for decision problems such as N-Queens
    Show answer

    Answer: C. It uses a bound on the best achievable objective to prune branches of an optimisation problem

    Backtracking prunes when a constraint is violated. Branch and bound, used for optimisation problems such as 0/1 knapsack or the travelling salesperson problem (TSP), also computes an upper or lower bound for each node and prunes any branch that cannot beat the best solution found so far.

  10. The Floyd-Warshall all-pairs shortest-path algorithm is an example of which technique?

    1. Greedy
    2. Dynamic programming
    3. Divide and conquer
    4. Backtracking
    Show answer

    Answer: B. Dynamic programming

    Floyd-Warshall defines d_k(i, j) as the shortest path using only intermediate vertices 1 to k, and builds it from d_(k-1) values in a table. That is a DP recurrence over overlapping subproblems.

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.

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.