Algorithm Learning/O(1) - Constant Time

O(1) - Constant Time

If you already know where it is, you don't wander. The fastest O(1).

EasyBasicsComplexity

Definition

O(1) is "Constant Time", where you know the location or can calculate it, finishing instantly regardless of N.

Key Characteristics

  • Jump directly to address
  • 1 Billion items? Still 1 step

Use Cases

Used in these scenarios:

📍

Array Index Access

arr[5] accesses instantly with one address calculation

🔑

Hash Table Lookup

HashMap.get() jumps directly via hash

📚

Stack Push/Pop

Only touches the top, always O(1)

🚶

Queue Operations

Only touches front/back ends

Complexity

Time Complexity

Best
O(1)
Average
O(1)
Worst
O(1)

Space Complexity

O(1)

Understand Deeper with Visualization

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

Start Visualization