   Chapter 11.5, Problem 8ES ### Discrete Mathematics With Applicat...

5th Edition
EPP + 1 other
ISBN: 9781337694193

#### Solutions

Chapter
Section ### Discrete Mathematics With Applicat...

5th Edition
EPP + 1 other
ISBN: 9781337694193
Textbook Problem
1 views

# Exercises 8—11 refer to the following algorithm segment. For each positive integer n, let a n be the number of iterations of the while loop. while   ( n > 0 ) n : = n   d i v   2 end while8. Trace the action of this algorithm segment on n when the initial value of n is 27.

To determine

Trace the action of this algorithm segment on n when the initial value of n is 27.

Explanation

Given information:

refer to the following algorithm segment. For each positive integer n, let anbe the number of iterations of the while loop.  while ( n > 0)

n := n div 2

end while

Calculation:

Given:

while (n>0)

n:=n div 2

end while INITIAL ASSIGNMENTS:

Initially, we set the value of n to 27.

We write this information down in a trace table.

 Iteration 0 n 27

FIRST ITERATION:

We next divide n = 27 by 2

2 13 27   207    61

We note that the quotient is 13 while the remainder is 1. We then assign the quotient of 13 to n.

n= quotient = 13

Writing this information down in the trace table, we obtain:

 Iteration 0 1 n 27 13

SECOND ITERATION:

We next divide n = 13 by 2

26 13   121

We note that the quotient is 6 while the remainder is 1. We then assign the quotient of 6 to n.

n=quotient = 6

Writing this information down in the trace table, we obtain:

 Iteration 0 1 2 n 27 13 6

THIRD ITERATION:

We next divide n = 6 by 2

23 6  60

We note that the quotient is 3 while the remainder is 0

### Still sussing out bartleby?

Check out a sample textbook solution.

See a sample solution

#### The Solution to Your Study Problems

Bartleby provides explanations to thousands of textbook problems written by our experts, many with advanced degrees!

Get Started 