Question: Look at the function loop6(n) defined hereLinks to an external site.. You may suppose that its argument n is a non-negative integer. We ignore the

Look at the function loop6(n) defined hereLinks to an external site.. You may suppose that its argument n is a non-negative integer. We ignore the possibility of integer arithmetic overflow. 1(a). Give a estimate for the value of loop6(n), as a function of n. (An exact formula is possible.) 1(b). Give a short argument to justify your answer in part (a). (Please use sentences, not just formulas.)

// How many iterations, as a function of n?

function loop6(n)

{

var i=2, iters=0

while (i <= n)

{

i = i*i

iters++

}

return iters

}

for (n=1; n<=65536; n=2*n)

print("loop6("+n+") took " + loop6(n)+ " iterations")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!