Understanding Time complexity of recursive functions

preview_player
Показать описание
Hi, in this video i will show how to analyse Time Complexity of a function with multiple recursion calls.
Рекомендации по теме
Комментарии
Автор

Really straight to the point, likedd it.

ParthPaTeL-wmkt
Автор

It was very clear to understand. Thank you..

Alptugaydin
Автор

thank you, this was extreamly helpfult and straight to the point

elhouarizohier
Автор

Should we express the depth of the tree as 'N', or as a function of 'n' ( the size of the input ) ?
Lets say that instead of "f( n - 1 ) + f( n - 1 )", the recursive call was "f( n / 2 ) + f( n / 2 )", in this case the depth would change, and as a result, the Time Complexity would also change.

dhruvsaraswat
Автор

Wouldn't it by 2^n-1? Because f(2) gives 2 outputs, f(3), gives 4 outputs (2^2), f(4) gives 8 outputs (2^3), and so on.

roomswilldo
Автор

What if in the recursive call, n reduces by 2, 3... instead of 1? I guess the depth would be reduced.

Vikasslytherine
Автор

I followed your procedure but I am getting some wrong answer:

code:
def factorial(n):
if n < 0: # O(1)
return -1 # O(1)
elif n == 0: # O(n)
return 1 # O(n)
else:
return n * factorial(n-1) # O(n)

print(factorial(3))

## O( branches ^ depth)
* Here the function calls 3 times, So = O(N 3)

But the real answer is O(N) only Why?

thepresistence
join shbcf.ru