O(1)

Constant Time

Dream

The fastest possible — input size simply does not matter.

Mental model

Think of a row of numbered post-office boxes. Box #47 is always at slot 47. You walk straight to it — whether there are 10 boxes or 10 million makes absolutely no difference.

Interactive Visualisation
🏣  Think of a row of numbered post-office boxes. Box #7 is always at slot 7 — no searching needed. Whether there are 10 boxes or 10 million, you go straight to it in one step.
Array size:
0
1
2
3
4
5
6
7
8
9
10
11

How it scales — (spoiler: it doesn't)

81 op
121 op
161 op
241 op
1001 op
1M1 op

How it scales

n = 1

1 op

n = 100

1 op

n = 10,000

1 op

n = 1,000,000

1 op

Next

O(log n)Logarithmic Time