Advertisement
naren_paste

Recursion relation_3(1)

Nov 28th, 2023
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | Source Code | 0 0
  1. a. T(n) = 2T(n-1) +1
  2.             T(n)
  3.            /    \
  4.       T(n-1)      T(n-1)
  5.         /  \          /   \
  6.     T(n-2) T(n-2) T(n-2) T(n-2)
  7.       ...   ...   ...   ...
  8.        |     |     |     |
  9.  
  10. for k times
  11. LEFT SIDE              RIGHT SIDE
  12. n-k=0                   n-k=0
  13. Now, let's calculate the cost at each level:
  14.  
  15. Level 0: 1T(n)
  16. Level 1: 2T(n-1)
  17. Level 2: 4T(n-2)
  18. Level 3: 8T(n-3)
  19. .
  20. .
  21. .
  22. T(n)+2T(n−1)+4T(n−2)+8T(n−3)+…+2^kT(n−k)
  23. if we sub n-k=1 i.e. k=n-1 we get base case condition
  24. T(n)+2T(n−1)+4T(n−2)+8T(n−3)+…+2^(n-1)T(1)
  25. by geometric progression
  26. T(n)=2^n-T(1)
  27. O(2^n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement