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?
23
Upvotes
View all comments
Show parent comment
1
u/Classic-Try2484 May 30 '25
That’s not true. In other recursive functions you cannot amortize the cost. Besides in analysis we always have to consider what happens as n and k get large. And the average cost won’t be constant unless you can memoize.
I am saying the first call to fib(n) results in n calls. This is often true of other recursive functions. But here only the first call triggers n calls. But to analyze an only the first call rather than average of many calls is not how the analysis is done.