• edited by
854 views
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$ );
\}

  1. $\Theta(\mathrm{n})$
  2. $\Theta\left(n^{2}\right)$
  3. $\Theta\left(2^{n}\right)$
  4. $\Theta$ (nlogn)

1 Answer

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
Position:
Show:

Related questions

2 2 votes
1 1 answer
1.7k
1.7k views
thepeeyoosh asked Jan 11, 2018
1,742 views
Consider the multi selection problem:Given a set ' S ' of n elements and set ' K ' of ' r ' ranks $\mathrm{K}_{1}, \mathrm{~K}_{2}, \mathrm{~K}_{3}$, $\qquad$ $\mathrm{K}...
1 1 vote
1 1 answer
1.9k
1.9k views
Kaluti asked Dec 6, 2017
1,874 views
Consider Bottom-up mergesort working on ' $n$ ' elements. Assume ' $n$ ' is a power of 2 . The minimum number of comparisons in order to get sorted list is$\frac{n \log n...
3 3 votes
2 2 answers
3.4k
3.4k views
rahuldb asked May 10, 2017
3,384 views
Please show the workingConsider a Quick-sort algorithm that always selects $(n / 5)^{\text {th }}$ smallest as the pivot element using $\mathrm{O}(\mathrm{n})$ time algor...
0 0 votes
2 answers 2 answers
774
774 views
rahul sharma 5 asked Dec 14, 2016
774 views
How is master theorem applicable here?A certain problem is having an algorithm with the following recurrence relation:\[T(n)=2 T\left(\frac{n}{\sqrt{2}}\right)+n, \quad T...