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,396 pages⌘K
  • 2,629 algorithms
  • 432 data structures
  • 1,614 problems
  • 2,410 proofs
  • 2,719 implementations in 10 languages
  • 3 scenes
  • 0-1 BFS

    Shortest paths in graphs with weights 0 or 1 using a deque, in linear time.

    Θ(n + m) worst1 languagesintro
  • 1/e stopping rule

    Observe the first ⌊n/e⌋ candidates without hiring, then hire the first one who is better than all before. It hires the best with probability tending to 1/e.

    Θ(n) worst1 languagesintro
  • 2-SAT

    SAT where each clause has at most two literals. It is solvable in linear time with the implication graph, while its counting and maximization versions are hard.

    intro
  • 2-SAT algorithm

    Solve 2-SAT in linear time. Find the strongly connected components of the implication graph; UNSAT when a variable and its negation share one, else read a model from their order.

    Θ(n + m) worst · best1 languagesintro
  • 2P-Set

    A replicated set built from two grow-only sets, one of added and one of removed elements. Remove wins over a concurrent add, and a removed element can never be added again.

    Θ(m) expected1 languagesintro
  • 3-SAT

    SAT restricted to clauses of at most three literals. It is NP-complete by Karp's reduction from SAT, and the best known algorithms take about 1.307^n time.

    intro

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.