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 (1).
j = 2 * j;
}
i = i/2;
}
:
Answer Posted / muhammad ijaz khan
The outer loop divides the working area in half in each
iteration. So the running time of this algorithm is
proportional to the number of times n can be divided by 2.
The inner loop will be executed unlimitted time. So
the time complexity of the outer loop will be the function
of ln and the total time is: T(n)= n*ln n
| Is This Answer Correct ? | 10 Yes | 20 No |
Post New Answer View All Answers
how to create user name stape by stape in cisco router {with command}
what is the difference between a decision statement and ea loop statement?
consiteunts of indian railways
Differentiate y = sinx + cosx + tanx
How do trains go around bends?
I want to join for load runner training..please suggest me which is the best institute for load runner training in bangalore?
How to Shut-down the system through QTP Script?
as we know that java is a platform independent language, but we need jvm for the same operating system why?
there are 50 users in a network, one system is virus affected , how to find that virus affected system?
plz send me interview questions & answers of Data Structure
tell the function of Source record of DNS server. why we create Stub zone? Tell Round Robing also?
sir , i am prparing for IOCL engineergin post please send me the old placement papers
how bluetooth works?what is principle behind in it?
how convert the spiral model to prototype model ?
Write a program to input 10 elements in an array and seperate even and odd numbers, positive and negative between them ?