Algorithm Search⌘K

Algorithms, explained, proved and run.

Each page explains one algorithm or idea in plain words. It gives the pseudocode, a proof that you can check, the cost, code with tests in many languages and a picture that you can step through.

Search 8 pages⌘K
  • 3 algorithms
  • 0 data structures
  • 2 problems
  • 3 proofs
  • 30 implementations in 10 languages
  • 3 scenes
  • Binary search

    Find a key in a sorted array. Compare the key with the middle item, and keep only the half that can hold the key.

    Θ(log n) worst · average10 languagesvisualintro
  • Insertion sort

    Sort an array one item at a time. Take the next item and move it left until the item before it is not larger.

    Θ(n²) worst · average10 languagesvisualintro
  • Loop invariant

    A statement about the variables of a loop that is true before each step. It is the main tool to prove that a loop is correct.

    intro
  • Merge sort

    Sort an array by divide and conquer. Sort each half, then merge the two sorted halves into one sorted array.

    Θ(n log n) worst · average · best10 languagesvisualintro
  • Search in a sorted array

    Given a sorted array and a key, find an index of the key, or report that the key is not in the array.

    Ω(log n) worstintro
  • Sorting

    Put the items of a sequence in non-decreasing order by a key.

    Ω(n log n) worstintro

See it run

All scenes

Languages

All languages

How a page earns trust

  1. Plain words. The text uses short sentences and simple words. A reader who knows some code can follow it.
  2. Proof. A human proof shows why the algorithm is correct. A Lean proof lets a computer check it.
  3. Tests. Each implementation has native tests. The build runs them in a pinned toolchain.
  4. Honest badges. The build computes each badge from evidence. Nobody writes a badge by hand. Read about the badges.