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 / 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


Please Help Members By Posting Answers For Below Questions

Explain how to share outlook calenders and the type of permissions you need to assign?

1665


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

1535


compair and contrast procedrual and object oriented programming language

1321


Which is better field cad/cam in mechanical or film editing/animation is better salary wise?

1440


how will u test the idoc

1565






What is the strongest naturally occurring material and how can it be cut?

608


what are the simlerities between macro and subroutine

1473


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?

1730


what is node class?

1755


Why DG Set manufacturers do not give options for alternative fuels. They even do not allow to change at the cost of custmers.

1375


#include int fn(int v); main() { printf("%d\n",fn(7)); } int fn(int v) { if(v==1 || v==0) return 1; if(v%2==0) return fn(v/2)+2; else return fn(v-1)+3; }

1520


how to make resume and what should I include in it?

1759


WHAT IS THE PROPER LOCATION OF SAMPLE POINT OF LPG SPHERE TANK?

1963


Why do windmills never appear stationary?

953


why dijkstra algorithm not used for negative weighted edges graph??

1623