8 ms·
It takes the same (huge) amount of time for all inputs - there's no early exit it always scans to INT_MAX. Hence O(1)
by devmop 4y ago
It takes the same (huge) amount of time for all inputs - there's no early exit it always scans to INT_MAX. Hence O(1)
- glitchc 4y agoThis is incorrect. Putting a finite bound on n does not reduce n to 1. n is always meant to be a finite arbitrarily large value. n=INT_MAX qualifies as arbitrarily large, especially on a 64-bit system.
- carnitine 4y agoO(x) = O(1) if x is some finite constant.
- PhineasRex 4y agoThere is no bound on n, it always searches to INT_MAX regardless of n.
- Sohcahtoa82 4y agoBig-O notation says nothing about the overall absolute size. All that matters is how the amount of work scales with the input value. If an algorithm will always take 1 billion years to complete regardless of the input, then it's still O(1).
- 8note 4y agoConsider n=INT_MAX*2 or INT_MAX^2 though. The behaviour does flatline as n approaches infinity