About Mastering Algorithms

Mastering Algorithms is a free reference for computer science algorithms and data structures. It covers 36 topics across sorting, searching, graphs, trees, dynamic programming, greedy algorithms, string processing, cryptography and machine learning — each with a plain-language explanation, a complexity analysis, a worked example traced step by step, and runnable Python.

What This Site Tries To Do Differently

There is no shortage of algorithm tutorials online. Most of them share the same problems: code that does not run, complexity claims that do not match the implementation shown, and worked examples whose numbers were never actually checked. Those errors get copied from site to site and are surprisingly hard to notice, because the prose around them sounds authoritative.

This site is written against three rules:

  • The code runs. Every Python listing is executed before publication. Sorting algorithms are tested against sorted() over thousands of randomised inputs; pattern-matching algorithms are tested against brute force; the neural network's backpropagation is checked against numerically estimated gradients.
  • The examples are traced, not invented. Every step-by-step walkthrough is generated from the algorithm as published on the page. If the trace says a partition produces a particular array, that is what the code on the same page actually produces.
  • The caveats are included. Where an implementation has a limitation — radix sort silently corrupting negative numbers, quicksort degrading on duplicate-heavy input, a heuristic that breaks A*'s optimality guarantee — the limitation is stated rather than quietly omitted.

Editorial Review

In August 2026 the entire site underwent a line-by-line correctness and currency audit. All 36 chapters were re-checked: every complexity bound, every worked example re-traced by hand, and every code listing extracted and executed. Fifty-eight corrections were applied as a result.

The substantive ones are worth naming, because they are the same errors that circulate widely elsewhere:

  • The Timsort implementation was replaced. The previous version omitted natural run detection entirely, which meant it was bottom-up merge sort wearing Timsort's name and did not have the adaptive O(n) best case the page claimed.
  • Big-O, Omega and Theta were being defined as worst, best and average case. They are not the same thing — asymptotic notation bounds a function, while case analysis chooses which function you are bounding.
  • The cryptography chapters were brought up to date: password-hashing guidance now points to Argon2id rather than salted SHA-256, key-exchange guidance reflects that TLS 1.3 removed RSA key transport in 2018, and the post-quantum standards finalised in 2024 are covered.
  • Several worked examples contained arithmetic that did not follow from the algorithms above them, including a quicksort partition trace and an A* path that ran through a wall.

Corrections are applied to the affected page rather than logged separately. If you find an error, please report it — it will be checked and fixed.

Who This Is For

  • Students working through an algorithms course who want a second explanation alongside their textbook.
  • Engineers preparing for interviews — most chapters link to the relevant LeetCode problems and explain the pattern rather than just the answer.
  • Working developers who need to remember how a specific algorithm behaves, what it costs, and where it breaks.

The material assumes you can read Python and are comfortable with basic programming constructs. It does not assume a mathematics background; where a proof matters, it is explained in words first.

How To Use It

The chapters are ordered so that each builds on the last — complexity analysis, then recursion, then trees, then the algorithm families that depend on them. You can read straight through, or use the chapter index as a reference and jump to whatever you need.

Everything on the site is free to read, with no account, paywall or newsletter signup. The site is supported by advertising, which is disclosed in our Privacy Policy.

Get In Touch

Corrections, questions and suggestions for new topics are all welcome. See the contact page, or email masteringalgorithms@gmail.com directly.