O(1) - Constant Time
August 31, 2026 · 3 min read · Angelos Ioakeimidis
O(1): The Best Possible News Your Algorithm Can Give You
What’s the fastest an algorithm can possibly be, in terms of how it scales? If you guessed “the one that doesn’t care how much data you throw at it”, you’re already thinking in O(1) terms, and that’s exactly what we’re digging into today.
What O(1) Actually Means
O(1) describes algorithms that take the same amount of time to compute no matter how big the input gets. Constant time complexity means the runtime never grows beyond a fixed, constant size. Give it 10 items or 10 million, it shrugs and does the same amount of work either way.
Generally speaking, the operations that fall into this bucket are the small, direct ones: primitive operations like addition, multiplication, subtraction, and division; assignment operations; accessing operations; and checking operations. None of these need to “look around” at the rest of your data to get their job done, which is exactly why they stay constant.
Where You’ll Actually See It
A few everyday examples of constant time operations:
- Finding out if a number is even or odd
- Checking if a specific item in an array is null
- Printing the first element from a list
- Finding a value in a hash map
Notice the pattern? Each of these grabs exactly what it needs and stops. No scanning, no looping, no “let me check everything just to be safe”.
Calculating O(1) in Practice
Let’s actually prove it instead of just taking my word for it. Here’s a function running against three arrays of wildly different sizes: 10 items, 100 items, and 100,000 items.
const apples = new Array(10).fill('apple').map((value, index) => `${value}${index}`)
const oranges = new Array(100).fill('orange').map((value, index) => `${value}${index}`)
const bananas = new Array(100000).fill('bananas').map((value, index) => `${value}${index}`)
function getFruits(arr) {
let t0 = performance.now()
console.log(arr[0]) // O(1) operation
console.log(arr[1]) // O(1) operation
let t1 = performance.now()
console.log(`Function was running for ${t1 - t0} milliseconds`)
// O(1 + 1) = O(2) => O(1)
}
getFruits(apples)
getFruits(oranges)
getFruits(bananas)Run this, and the time taken in all three cases comes out to basically 0.0 seconds.
Every single time. Isn’t that kind of the whole point?
Here’s why that happens:
- We’re only ever pulling the first and second elements of the array, regardless of how big that array actually is.
- We’re never looping over the whole thing. Not even a peek.
- We’re performing two
O(1)access operations, which technically gives usO(2). - And per the constant rule, we drop that down to
O(1). A 100,000-item array costs exactly the same as a 10-item one here, because we simply never touch the other 99,998 items.
That’s the magic of O(1) in a nutshell: the size of the haystack is completely irrelevant when you already know exactly where to look.
Why This Matters
If you ever find yourself designing something that needs to run fast no matter how much your data grows, O(1) is the dream. It’s the reason hash map lookups are so beloved, and it’s the standard every other complexity class gets measured against. Everything else on the Big O scale, in some way, is a story about how far an algorithm drifts from this ideal as your input grows. So next time you write a function that reaches directly for what it needs instead of searching for it, give yourself a little credit. You just wrote O(1) code.
O(1) means runtime stays fixed regardless of input size - a 10-item array costs the same as a 100,000-item one.
The tell-tale sign of O(1) is direct access, not searching - grabbing a known slot, not scanning for one.
Constants get dropped: two O(1) operations back to back is O(2), which collapses right back down to O(1).
O(1) is the benchmark every other complexity class is measured against - it never degrades as data grows.
Liked this article? Share it with a friend on Twitter or support me to take on more ambitious projects to write about. Have a question, feedback or simply wish to contact me privately? Shoot me a DM and I'll do my best to get back to you.
Have a wonderful day.

Angelos Ioakeimidis
Data Science & AI Student. Writing about software engineering, design, and AI.