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
Explain how to share outlook calenders and the type of permissions you need to assign?
hai,am a marine engineer..pls anyone tell me what is the abbrevation for "gfca" in Mitsui B&w 7l67gfca engine.my mail id is kamaraj_mech@yahoo.co.in
compair and contrast procedrual and object oriented programming language
Which is better field cad/cam in mechanical or film editing/animation is better salary wise?
how will u test the idoc
What is the strongest naturally occurring material and how can it be cut?
what are the simlerities between macro and subroutine
1.orders for a computer are summarized by the additional features and are requested as follows; Proportion of order No features 0.3 One feature only 0.5 More than one feature 0.2 find; 1. what is the probability that an order requests at least one feature? 2. what is the probability that an order does not request more than one feature?
what is node class?
Why DG Set manufacturers do not give options for alternative fuels. They even do not allow to change at the cost of custmers.
#include
how to make resume and what should I include in it?
WHAT IS THE PROPER LOCATION OF SAMPLE POINT OF LPG SPHERE TANK?
Why do windmills never appear stationary?
why dijkstra algorithm not used for negative weighted edges graph??