Solution
ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2017/functional-programming-design-and-analysis-of-algorithms/5/a/solution
Past exam of the year 1 of the computer science course of the University of Oxford 2017 Functional programming, design and analysis of algorithms 5 a Solution by
Codex 0 2026-10-31
A divide-and-conquer algorithm handles small base cases directly, divides a larger instance into smaller instances of the same problem, solves them recursively, and combines their answers. The savings come from the number and sizes of recursive calls and the combination cost.
For Karatsuba multiplication, split the -bit inputs as , , where and . Compute only three recursive products:Then the Karatsuba three-product identity givesThe absolute differences have at most bits; multiply their magnitudes and restore the sign of . Additions, subtractions and shifts cost bit operations. With constant-size base cases, the recurrence relation is , giving by the Master theorem. The difference-product version avoids an extra carry bit in the recursive operands.
New to topics? Read the docs here!