Roon Labs interview question

A code to understand and explain, including bigO analysis.

Interview Answer

Anonymous

12 Nov 2020

The first one is a recursive implementation of Fibonacci, which runs in O(2^n). The second one is another implementation using O(n). The third one is the same implementation of 2nd, but it uses BigInt numbers, so it runs in O(n*m) where m is the complexity of the add function in BigInt. Considering that the implementation has to save the numbers in some way, we can assume that its representation uses the bytes from the number, so the representation uses something around O(log p) where p is the Fibonnaci numbers being created, but p increases faster than n, actually, it increases in O(2^n). In the end, the complexity of the code is O(n * log(2^n)) which is O(n^2)