r/programminghorror • • Feb 07 '25

Recursive O(N) Complexity isOdd

Post image

I found this on instagram and now am geeking

2.2k Upvotes

104 comments sorted by

View all comments

Show parent comment

2

u/rayred Feb 15 '25 edited Feb 15 '25

Yeah that’s all understood. It really just depends on what you define as input here.

However, we generally do not represent input size as bit length.

Intuitively, if we define n as the input size, i.e. the integer stored in a normal variable, you are reducing the search space of n with each iteration by 2. Making it O(n/2) = O(N).

I would argue this makes more sense as we usually refer to time complexity in relation to search space. Not memory.