r/computerscience • u/dashdanw • May 27 '25
Discussion Does memoizing a function make it truly "idempotent"?
If you cache the result of a function, or say, for instance, check to see if its already been run, and skipping running it a second time make a function truly idempotent?
21
Upvotes
View all comments
Show parent comment
1
u/Classic-Try2484 May 30 '25 edited May 30 '25
I might disagree with this implementation. But correctly written it is O(1). Or perhaps you didn’t see amortized analysis.
One can also argue a first call to fib(k) will generate k calls as the function is recursive so n == k even on the first call