by ralusek · 4y ago · 0 comments
Functionally, though, I would describe this algorithm as O(N). It's just a straight up linear scan of the problem space. It's unbounded, with a worst case of O(Infinity) and no upper limit on what searched can be, but it's functionally O(N) regardless.
O(1) needs to basically be something like a hash key/pointer to memory address to get the result you're looking for. It will not increase linearly as the problem space increases, whereas your first example increases exactly linearly.
In the end, it's just not a useful way of modelling the problem.
If an algorithm will always take 1 billion years to complete regardless of the input, then it's still O(1).
The behaviour does flatline as n approaches infinity