1 1 vote Determine the aspmptotic running time of $f(n)$. int f(int n) \{ int $x$; if $(\mathrm{n}==0) x=1$; else $x=f(\mathrm{n}-1)^{*} 2$; $\mathrm{g}(x)$; return $x$; \} void g(int m) [ int $y$; for ( $y=m ; y>0 ; y /=2$ ); \} $\Theta(\mathrm{n})$ $\Theta\left(n^{2}\right)$ $\Theta\left(2^{n}\right)$ $\Theta$ (nlogn) Algorithms algorithms time-complexity test-series + – nikkey123 854 views answer comment Share Follow Print See all 4 Comments 4 4 Comments reply Anu007 commented Jan 3, 2018 i edited by Anu007 Jan 4, 2018 reply Follow flag is it O(n2) F(n) = time complexity of G(n) G(n) = log(2) + log(4) + log(8).............+log(2n) = 1+2+3+4+5+..........+n =O(n2) 0 0 replyShare nikkey123 commented Jan 3, 2018 reply Follow flag answer given is O(n^2) 0 0 replyShare sourav. commented Jan 3, 2018 reply Follow flag it should be D) $T(n)=T(n-1)+ \log n$ $T(n)=\log n+\log n-1 +\log n-2 +...\log 2$ $T(n)=\log (n \times n-1 \times n-2 \times.. 2)=\log(n!)=\Theta (n \log n)$ 0 0 replyShare nikkey123 commented Jan 3, 2018 reply Follow flag but the complexity of function g changes with the value of x 1 1 replyShare Please log in or register to add a comment.
0 0 votes else loop will be executed for (n-1) times g(x) is also executed for (n-1) times as after every else g(x) should be executed. for better understanding draw the tree for some smaller input again g(int m) function is executed for (1+logx) times time complexity wil be (n-1)(n-1)(1+logx) = O(n^2) where (1+log x) can be omitted because of smaller value. If I am wrong then plz correct me $ruthi answered Jan 7, 2018 $ruthi comment Share Follow 0 reply Please log in or register to add a comment.