Module 3 · Math for DSA

Math Drills

Concept~5 min

The Archivist's fire drill

The Master Archivist runs one final exercise before you're trusted alone in the stacks: a rapid-fire round of real scenarios, no time to reach for a calculator or re-derive a formula from scratch. Same protocol as the Big O drills: commit to an answer before touching the quiz, and when you miss, find the rule you misapplied, not just the right letter.

Drill 1 — logs in disguise

The Archivist asks: "We have a balanced branching cabinet holding 10⁹ index cards. How many drawer-checks does one lookup cost?"

Check yourself

1 question

01

Drill 1 — lookups in a balanced tree of 10⁹ items cost about…

Drill 2 — the JS modulo trap

The carousel spins backward, and one assistant reports a slot number that doesn't physically exist.

def prev_index(i: int, n: int) -> int:
    return (i - 1) % n

Check yourself

1 question

01

Drill 2 — which implementation is buggy, and when?

Drill 3 — huge products

The Archivist's overflowing ledger: 10⁵ numbers, each up to 10⁹, must be multiplied together and reported modulo 10⁹+7.

Check yourself

1 question

01

Drill 3 — correct approach in TypeScript?

Drill 4 — counting the search space

The shipping crate can hold n ≤ 12 books, and the Archivist wants the exact shelf order that minimizes handling penalty.

Check yourself

1 question

01

Drill 4 — what does n ≤ 12 tell you?

Drill 5 — Euclid, by hand

Two archivists need the biggest shared carton size for deliveries of 252 and 105 books, by hand, no calculator.

Check yourself

1 question

01

Drill 5 — gcd(252, 105) = ?

Drill 6 — sieve or test?

The front desk fields q = 10⁵ requests in a row, each asking whether some shipment size n ≤ 10⁷ is packable one-at-a-time (prime).

Check yourself

1 question

01

Drill 6 — sieve up front, or trial-divide per query?