discrete mathematics Consider the following code snippet co

// discrete mathematics
Consider the following code snippet: count = n while count > 1: # ----- count = count/2 Assume that division is without remainder or decimal, e.g. 17/5 = 3, not 3.4. Also assume that n is a power of 2, so n = 2^k. How many times is the line #--- run?

Solution

Initially count=n

After executing the while loop for the first time the value of count changed to count=n/2

After executing the while loop for the second time the value of count changed to count=n/4

After executing the while loop  for the mth time the value of count changed to count=n/2m

n/2m>1

2k/2m>1 is true till m=k-1

and while loop executed initially

so number of times = k-1+1=k

// discrete mathematics Consider the following code snippet: count = n while count > 1: # ----- count = count/2 Assume that division is without remainder or

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site