Pecan_
Pecan_

Reputation: 27

Computing Big-O for multiple recursive calls where one is logn and the other is linear

def f(n):
    if n <= 1: 
        return 1
    return f(n-1) + f(n//2)

here n//2 is n divided by two truncated towards zero, so 3//2 is 1.

I've got this problem in my algorithms class. From my understanding it should be exponential.

The f(n-1) call dominates, the depth of the tree is at least n. At each branch of the tree you should have two calls making it exponential. The f(n//2) wont contribute anything to complexity because its being dominated.

The options I've been given are:

None of them make sense to me for this context.

For clarity I'm not interested in the answer as much as I am the reasoning. This is big-O not theta, there are multiple answers. I believe the best big-O to be nlogn. As supported by a combination of n and logn recursive calls. However it is possible that bound is too low. I'm hoping someone has an intuitive answer to understanding these kinds of recursive big-o questions.

Upvotes: 1

Views: 78

Answers (0)

Related Questions