1

I was reading the most voted answer from here: Difference between Divide and Conquer Algo and Dynamic Programming, but I don't have enough reputation to comment so I have to post a new question.

My question is: why is the overall time O(n)?

To my understanding, finding an element from an unsorted array of size n can cost time n.

And in the case of finding the fibonacci number, the worst case to check if a number is in memo could cost n time, so the whole algorithm will repeat n times, and each time it'll search for the number once, which costs n time. Then the overall time should be O(n^2) instead of O(n).

Could anybody point out where I misunderstood? Thanks

Yi Shi
  • 11
  • 1

1 Answers1

0

Due to memoization the asymptotic complexity becomes O(n).

Searching of the memoized fibonacci is not O(n), It is O(1) considering you are using array not a LinkedList.

Avishek Bhattacharya
  • 6,534
  • 3
  • 34
  • 53