2,387 views
6 votes
6 votes

Consider the following program:

int Bar(int n){
    if(n<2) return;
}
else{
    int sum=0;
    int i,j;
    for(i=1;i<=4;i++) Bar(n/2);
    for(i=1;i<=n;i++){
        for(j=1;j<=i;j++){
            sum=sum+1;
        }
    }
}

Now consider the following statement

$S_{1}:$ The time complexity of $Bar\left ( n \right )$ is $\Theta \left ( n^{2}logn \right )$

$S_{2}:$The time complexity of $Bar\left ( n \right )$ is $\Omega \left ( n^{2}logn^{2} \right )$

$S_{3}:$The time complexity of $Bar\left ( n \right )$ is $O \left ( n^{3}logn^{2} \right )$

How many statements are correct________________

1 Answer

Best answer
4 votes
4 votes

All statements are correct.

Above program recurrence relation is,

T(n)=$4T(n/2)+n^2$

Now if we solve above recurrence equation with Master Theorem then we will get complexity as :

Θ($n^2logn$)


Now we can write $n^2logn^2$ as $n^2* 2logn$ so $n^2logn$ = Ω($n^2logn^2$)

Now last function is  $n^3logn^2$ and obviously $n^2logn$ = O($n^3logn^2$)

selected by

Related questions

0 votes
0 votes
1 answer
2
1 votes
1 votes
1 answer
3
Markzuck asked Jan 6, 2019
501 views
Please show the ideal way to deal with such comparisons as I am getting g>=f IN genral what logic shall be followed to analyse such complex comparions?
0 votes
0 votes
1 answer
4
Markzuck asked Dec 29, 2018
791 views
cant we write the recurrance relation for bar() as T(n) = 5T(n-1) + c,like cant we take both the recurrance call as combined as both have same parameter?and if not, then ...