Divide and Conquer

Context: FIT1008_MOC, FIT2004_MOC · a recursive strategy · powers Binary Search, Merge Sort, Quick Sort · solves the Sorting Problem FIT2004 use: the examinable examples are Merge Sort and Quick Sort; every D&C algorithm’s running time is found by solving the cost recurrence , where counts recursive calls and the combine.

Quick Revision

  • 🎯 Objective: divide into subproblems, conquer recursively, combine ➔ most efficient when splits are roughly equal.
  • 📦 Core Components: split ➔ recurse on parts ➔ combine | split balance sets the depth.
  • ⚡ Key Constraint: balanced halves → ; lopsided → ; single-half search → .

📝 Core

1. The Strategy (Divide / Conquer / Combine)

  • Divide ➔ split into subproblems; conquer ➔ solve each recursively + independently; combine ➔ merge solutions.
  • Base case ➔ size .
  • Efficiency condition ➔ best when subproblems are roughly equal in size ➔ depth .

2. Cost by Levels

  • Recursion tree ➔ total cost = (levels) × (work per level).
  • Balanced × = ; lopsided × = ; single-half + work ➔ .

3. Independence Assumption (vs DP)

  • Assumption ➔ subproblems are independent (non-overlapping), solved once.
  • Overlap break recomputing ⟹ exponential ➔ use memoisation / dynamic programming.

4. Adapting D&C to a NEW problem (the LO1 drill — Applied 2)

  • Three questions, in order ➔ (1) does the answer decompose additively across the split — within-left within-right cross? (2) can the cross term be computed in ? (3) does the per-call work shrink with the subproblem, or does the level sum refuse to decay?
  • Strengthen the recursive contract ➔ ask the recursion to return more than the answer. Counting Inversions is only because each call returns a sorted subarray as well as a count; that extra guarantee is what makes the cross term linear.
  • Question (3) is the one that gets skipped2D Local Maximum (Peak Finding) halves the matrix on the middle column and still costs , because the deciding scan stays full-length. Cutting both axes makes level cost .
  • On a new problem, the correctness argument is the deliverable ➔ “why is it safe to discard the other subproblems?” carries more marks than the pseudocode; state it as an explicit claim about what the kept subproblem is guaranteed to contain.

⚙️ Core Implementation

Split/combine trade-off: Merge Sort = trivial split, heavy combine; Quick Sort = heavy split, trivial combine; Binary Search = single-subproblem “decrease and conquer”.

🔹 The D&C skeleton

⚖️ Core Decision Matrix

Split balanceLevels × work/levelResultExample
Even halves × Merge Sort
One side ≈ all × Quick Sort worst
Single half, work × Binary Search
Single half, shrinking work — root-dominated2D Local Maximum (Peak Finding)
Both halves, combine × Counting Inversions
Overlapping subproblemsrecomputeexponential → DPnaive Fibonacci

When It Flips: balanced splits give depth ; lopsided ones push depth toward , collapsing to . Space: recursion stack ; merge-style combine adds scratch, partition-style is in-place.

📊 Exam Execution Trace

Manual Execution Trace

Recursion tree of a balanced D&C sort on :

Step / StateLevel# subproblemsSize eachWork this level
0 (Init)018
1124
2242
3381

levels, each .

Applied Exercise

Problem: Derive the balanced vs lopsided D&C recurrences. Derivation Proof / Hand-Calculation Walkthrough:

Final Extracted Output: split balance alone decides vs — the depth term dominates.

🧠 Active Recall