Browse curriculum

Mathematics

Mathematical Algorithms for Coding Interviews

Mathematical algorithms are the quiet prerequisite in a lot of interview questions. A problem is rarely stated as "compute a GCD" — it asks you to simplify a fraction, or to find when two cycles align, and the mathematics is the step you are expected to recognise on your own.

Each lesson here visualises the mechanism rather than the identity. You watch the Euclidean algorithm shrink a pair of numbers, see the Sieve of Eratosthenes strike out composites in passes, and step through fast exponentiation halving an exponent. Bit manipulation is included because interviewers reach for it constantly and it is the topic most often learned as a set of tricks rather than as a model.

6

Interactive lessons

3

Free to open

6

Languages (JS, TS, Python, Java, C, C++)

Lessons

Mathematics lessons

Complexity

Mathematics time and space complexity compared

Best, average and worst-case running time and extra space for every mathematics lesson, as each lesson derives them.

LessonBestAverageWorstSpace
GCD / LCMO(1)O(log(min(A, B)))O(log(min(A, B)))O(1)
Prime NumbersO(1)O(√N)O(√N)O(1)
Sieve of EratosthenesO(N log log N)O(N log log N)O(N log log N)O(N)
Modular ArithmeticO(1)O(1)O(1)O(1)
Fast ExponentiationO(log B)O(log B)O(log B)O(1)
Bit ManipulationO(1)O(1)O(1)O(1)
Curriculum

Continue the DSA curriculum

Mathematics is one of 12 topics in the interactive DSA visualizer curriculum. Once this topic is comfortable, the coding interview pattern library reorganises the same material around the patterns interview questions are built on.

Directory

Every other DSA visualizer