Numbers and recurrences

Fast algorithms for GCDs, primes and huge powers, then divide and conquer in general, with the master theorem for working out how fast a recursive method is.

About 6 hours of study

Learning objectives

Lessons

  1. 1

    Number algorithms

    Euclid's GCD, the sieve of Eratosthenes, and fast modular exponentiation: three old ideas used in every contest.

  2. 2

    Divide and conquer and the master theorem Intermediate

    Split a problem into smaller copies of itself, solve them recursively, combine the answers, and work out the running time with the master theorem.

Module practice

Module quiz

1. What is gcd(30, 12)?
2. What is lcm(4, 6)?
3. How many primes are there up to 20?
4. How many times does the repeated squaring loop run for b = 1024?
5. What does T(n) = 2T(n/2) + O(1) solve to?
6. What does T(n) = 4T(n/2) + O(n) solve to?
7. What does T(n) = 2T(n/2) + O(n²) solve to?

‹ Graph algorithmsStrings, grids and bits ›