0 0 votes Find the time complexity of the given program Algorithms made-easy-test-series algorithms time-complexity + – Nitesh_Yadav 936 views answer comment Share Follow Print See all 4 Comments 4 4 Comments reply anon1 commented Jan 4, 2022 reply Follow flag T(n)=T(n-1)+T(n-2)+T(n/2) = O(3^n) ..you can not ignore T(n/2) part. 2 2 replyShare Shoto commented Jan 4, 2022 reply Follow flag @raja11sep What if there was break; after every case? I think then the time complexity would be O(n) 2 2 replyShare Chhaatra commented Jan 4, 2022 reply Follow flag Yes @adad20, because then only case 1 will be executed. 1 1 replyShare anon1 commented Jan 4, 2022 reply Follow flag yes. 1 1 replyShare Please log in or register to add a comment.
0 0 votes T(n) = T(n-1) + T ( n-2 ) + T( n/2 ) + C T(n- 1 ) > T ( n-2 ) && T ( n -1 ) > T ( n/2 ) IF WE IGNORE THE T ( n /2 ) so T( n ) = 2 T ( n-1 ) + c from master method T ( n ) = a T ( n-b ) + n^k a>1 than solution = O ( n^k a^n/b ) here a= 2 & k= 0 so complexity = 0 ( n^0 2^n/1 ) = 0 ( 2^n ) IF WE NOT IGNORE THE T( n /2 ) T ( n) = 3T ( n-1 ) +c solution for is a= 3 k = 0 complexity = O ( n^k 3^n/1 ) = 0 ( 3^n ) now my dout is we have to ignore the T ( n/2 ) or not …...thanks ganesh gaitonde answered Jan 8, 2022 ganesh gaitonde comment Share Follow 0 reply Please log in or register to add a comment.