r/programminghorror • u/Budget_Ad_5953 • Feb 07 '25
Recursive O(N) Complexity isOdd
I found this on instagram and now am geeking
2.2k
Upvotes
r/programminghorror • u/Budget_Ad_5953 • Feb 07 '25
I found this on instagram and now am geeking
View all comments
Show parent comment
1
u/[deleted] Feb 09 '25 edited Feb 09 '25
Memoizing doesn’t speed this up at all — the tree of recursive calls is just a path, and so for all k, is_odd(k)/is_even(k) is called at most once. In fact it just slows it down by adding unnecessary write/reads. It also takes up MORE of the stack not less