Understanding the runtime of an algorithm has been the achilles heel in my understanding of computer science principles. Binary search keeps coming up as the prevailing example of logarithmic runtime. Common analogies include the dictionary and phone book examples. Are there other common or well-known examples (to non-beginners) that have a running time of O(log n)?
Asked
Active
Viewed 103 times
1
-
There could be infinite algorithms with O(logN) complexity, like searching/inserting in a balanced BST – Abhinav Mathur Apr 29 '21 at 17:59
-
naive integer version of `log2` (highest set binary bit search with bitshifting) – Spektre Apr 30 '21 at 07:23
1 Answers
0
Ancient Egyptian multiplication takes logarithmic time (on the unit-cost RAM). Ditto exponentiation by squaring (they’re very similar).
Also, operating on a tree of height h is often Θ(h), which is logarithmic when h = Θ(log n). Binary search trees are uncomfortably close to binary search, perhaps, but you also see log-height trees in priority queue algorithms.

David Eisenstat
- 64,237
- 7
- 60
- 120