AlgoViz

O(log n) logarithmic time

easy 14 min

O(log n) means each step cuts the remaining work by a constant factor, usually half.

Where it shows up

The same pattern appears across everyday software.

  • Database indexes

    Relational databases store indexes as B-trees or B+ trees. Each node holds hundreds of keys, so even a billion rows sit only three or four levels deep and a lookup reads just a few pages from disk.

  • Finding a bad commit with git bisect

    git bisect marks one good and one bad commit, then checks out the middle commit for you to test. Each answer halves the range, so 1,000 commits are narrowed to the culprit in about 10 tests.

  • Public-key cryptography

    RSA and Diffie-Hellman compute values like m^e mod n with exponents hundreds of digits long. Square-and-multiply needs only a few thousand modular multiplications, one or two per bit of the exponent.

  • Priority queues and schedulers

    Operating system schedulers, Dijkstra's algorithm and event simulators keep a binary heap. Pushing or popping walks one root-to-leaf path, which is O(log n).

  • Sorted maps in standard libraries

    Java's TreeMap, C++'s std::map and std::set are red-black trees, so insert, delete and lookup stay O(log n) even when keys arrive in sorted order.

  • Looking up a word or a name

    Finding a word in a dictionary or a name in a phone book by opening near the middle and halving is binary search done by hand.