Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is the time complexity T(n) of the nested loops
below? For simplicity, you may assume that n is a power of
2. That is, n = 2k for some positive integer k.
:
i = n;
while (i >= 1){
j = i;
while (j <= n) {
<body of the inner while loop > //
Needs &#61553;(1).
j = 2 * j;
}
i = &#61675;i/2&#61691;;
}
:

Answer Posted / arefe

hello I'm not sure about what I'm going to say . please tell me if you think it's wrong.
at first let's write some steps of it .
1) i = j = n
2) i = n/2 , j = n/2 --> j = n
3) i = n/4 , j = n/4 --> j = n/2 --> j = n
4) i = n/8 , j = n/8 --> j = n/4 --> j = n/2 , j = n
.
.
.
now if we count ,
the number of n , which j is equal to is log(n) ,
the number of n/2 , which j is equal to is log(n)-1 ,
the number of n/4 , which j is equal to is log(n)-2 ,
the number of n/8 , which j is equal to is log(n)-3 ,
and so on ,
so the result is summation log(n) - i , which i is from 0 to log(n) ,
we write log(n) out of Sigma and multiple it with log(n) + 1,( if we write Sigma term we have log(n) +1 , log(n))
and summation i , which i is from 0 to log(n) , is equal to (log(n)+1)(log(n))/2

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how to increase the chiller effiency?

1988


how convert the spiral model to prototype model ?

1677


What are the inspection and test plan for lift materials?

1996


how the parting surface is selected in injection mould

1908


Can one be shocked holding a wire carrying a very large current with a low voltage source?

1960


What is Moore's law and what limits the size of a computer chip?

1110


when air is supplied from larger diameter pipe with some pressure if change diameter to small pipe the pressure increases or not? also what is increased pressureor velocity?

1758


whether we can implement VPN based on UDP? If yes then tell how? If no tell why not?

1990


Can have i call constructor in interface?

2134


What is the difference between operator overloading and function overloading in C when compared with C++?

1795


i need NIC written test paper or give me any idea about written exam.Plz send me at smileever8@gmail.com

2205


What is the difference between "type testing" and "product qualification"?

1512


who is the judge in case of the auditor has raised an NCR against an auditee? who should decide weather this NCR is acceptable and the auditee has to accept?

1786


find the salary of an employee where employee number is known

1896


how to cable size by Amp with example

2621