Math for coding interviews/Constant time - O(1)

O(1) Constant Time, Explained Visually

No matter how large the input is, this operation always takes the same amount of time. The size of n simply does not matter.

See it for yourself

A perfectly flat horizontal line on a graph. The line never rises no matter how far right you go.

Constant time - O(1)

No matter how large the input is, this operation always takes the same amount of time. The size of n simply does not matter.

Visual: A perfectly flat horizontal line on a graph. The line never rises no matter how far right you go.

Think of it this way: Looking up a word in a dictionary if you already know the exact page number. It does not matter how thick the dictionary is.

For algorithms: Accessing array[3] is O(1) because the computer calculates the memory address directly: start + 3 * item_size. One calculation, done.

Real-world analogy

Looking up a word in a dictionary if you already know the exact page number. It does not matter how thick the dictionary is.

Why it matters in interviews

Accessing array[3] is O(1) because the computer calculates the memory address directly: start + 3 * item_size. One calculation, done.

Where it shows up on the learning path