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
Write a program to input 10 elements in an array and seperate even and odd numbers, positive and negative between them ?
requirement:To move display statements in a cobol program to a dataset.These display statements were not in main program but in calling program and we were not allowed to move these info via sysout dd dsn='dataset.name' . please let me know the ways this can be handled
What are the input documents to 1.Functional testing,2.System testing and 3.Integration testing. Whether there will be separate test cases for regression testing or functional testing?
difference between a for loop and a while loop? what are its uses in c language?
hi, please send me "state bank of india", last 5 years question paper with answers to my mail id.
what two ways you can use to ensure that visual basic does not allow uncleared variables?
what is b tree
i m doing my 3rd yr with only 6 month left to complete it..within this 6 months which is the best nd useful oracle certification program should i do??pls help me out!!
Can have i call constructor in interface?
What would be the difficulties with building a bridge that connects the UK and Canada?
Qatar petroleum will call me for an technical phone interview as safety officer Please let me know what kind of question they asked ? any idea about this written test ?
Explain power?
which/why unix commands are simpler rather than complex tasks
How will a tester be sure that He’s covered the entire functionality in his Test case and not missed out anything?
What are the differences between 1 dimensional RAM and 2 dimensional RAM?