liveBook · Manning

Logarithmic time complexity

As explained in Grokking Algorithms, Second Edition

Logarithmic time describes an algorithmic running time that grows in proportion to the logarithm of the input size.

Logarithmic time describes an algorithm whose running time grows with the logarithm of the input size. Each additional step can handle a much larger input, so growth stays slow as lists become bigger. section 1.10 section 1.5

Folding a grid

Drawing 16 boxes one at a time takes 16 operations, or O(n). Folding paper doubles the number of boxes each time: four folds produce 16 boxes, so the same task takes O(log n) time. section 1.8

Compare logarithmic growth with familiar running times:

  • Binary search uses O(log n): at most seven guesses find an item in 100 entries, and at most 32 guesses handle 4 billion entries. section 1.5
  • Simple search uses O(n), checking items one by one; logarithmic time becomes increasingly faster than linear time as the input grows. section 1.12
  • A balanced recursive process can have O(log n) levels, as in quicksort’s best-case call stack, although each level may add O(n) work. section 4.5
Run times for search algorithms

Use the search-runtime figure to compare logarithmic and linear growth visually. section 1.5

How Grokking Algorithms, Second Edition covers it

How deep it goes
Explains logarithmic growth through examples and comparisons, while simplifying operation counts and deferring fuller Big O treatment.
Examples
Uses binary-search guesses, folded grids, operation counts, and quicksort call stacks as concrete examples.
What you can do after
Evaluate whether an algorithm grows logarithmically and compare its scaling with linear and other common runtimes.
How it connects
Connects logarithmic time with Big O notation, binary search, linear time, recursion, and quicksort.

Also explained in

Compare how 4 books explain logarithmic time complexity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Algorithms, Second Edition. The section links point to the parts of the book it draws on.