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 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 .
  • Cost by levels ➔ total = (levels) × (work per level): balanced · lopsided · single-half with work .

2. Independence Assumption (vs DP)

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

3. 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 makes the cross term linear.
  • Question (3) is the one that gets skipped ➔ 2D Local Maximum (Peak Finding) halving on the middle column 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

Applied Exercise

Problem: Derive the balanced vs lopsided D&C recurrences.

Final Extracted Output: split balance alone decides vs — the depth term dominates. (Balanced tree on : levels, each .)

🧠 Active Recall