Algorithm Learning/O(log n) - Logarithmic Time

O(log n) - Logarithmic Time

Learn O(log n) with binary search. Discard half each time for incredible speed!

EasyComplexityBinary SearchLogarithm

Definition

O(log n) halves the work each step. Doubling data only adds one more step.

Key Characteristics

  • Eliminate half each time
  • Double data → +1 step
  • Sorted data required

Use Cases

Used in these scenarios:

🔍

Binary Search

Search by halving in sorted array

🌳

Binary Search Tree

Find, insert, delete in BST

⛰️

Heap Operations

Heapify follows tree height

Complexity

Time Complexity

Best
O(1)
Average
O(log n)
Worst
O(log n)

Space Complexity

O(1)

Understand Deeper with Visualization

See how the algorithm works through step-by-step animations and code execution.

Start Visualization