127k views
0 votes
Give a tight bound on the number of times the z = z + 1 statement is executed. i = 2 while ( i > 1 ) { i = floor(i/2) z = z + 1 }

1 Answer

5 votes

Answer:

zero ( 0) times.

Step-by-step explanation:

In the code;

i = 2

while ( i > 2){

i = floor( i/2 );

z = z + 1;

}

the variable " i " is assigned the integer " 2 ", then the while statement loops with a condition of a greater " i " value and divides the value by two for every loop.

But in this case, the while statement is not executed as the value of " i " which is 2 is not greater than but equal to two.

User Shane Bishop
by
5.0k points