Dynamic Programming Fibonacci algorithm

后端 未结 3 908
孤街浪徒
孤街浪徒 2021-01-25 02:40

I\'m working on an algorithm to calculate a Fibonacci number and got the pseudo code for it but I can\'t figure out how much time it takes to run. I think it runs at O(n) but no

3条回答
  •  余生分开走
    2021-01-25 03:21

    You are correct that this takes O(n) as you are just counting sequentially from 2 to n to fill your array. If you were doing some sort of lookup for each of the i-1 and i-2 numbers, that could increase complexity, but the way you have written it, you are calling a direct address for each of those values.

提交回复
热议问题