   Chapter 11.5, Problem 6ES ### 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

# In 5 and 6, trace the action of the binary search algorithm (Algorithm 11.5.1) on the variables index, bot, top, mid, and the given values of x for the input array a [ 1 ] = Chia ,   a [ 2 ] = Doug ,   a [ 3 ] = Jan ,   a [ 4 ] = Jim ,   a [ 5 ] = Jose ,   a [ 6] = Mary ,   a [ 7 ] = Rob ,   a [ 8 ] = Roy ,   a [ 9 ] = Sue ,   a [ 1O ] = Usha , where alphabetical ordering is used to compare elements of the array. 6. a. x = Amanda b. x = Roy

To determine

(a)

Trace the action of the binary search algorithm (Algorithm11.5.1) on the variables index, bot, top, mid, and thegiven values of x for the input array a  = Chia, a  = Doug, a  = Jan, a  = Jim, a  = José, a  = Mary, a  = Rob, a  = Roy, a  = Sue, a  = Usha, where alphabeticalordering is used to compare elements of the array.

Explanation

Given information:

x = Amanda.

Calculation:

a=Chia

a=Doug

a=Jan

a=Jim

a=Jose

a=Mary

a=Rob

a=Roy

a=Sue

a=Usha

Given: x = Amanda

INITIAL ASSIGNMENTS:

bot= bottom index of the array

top= top index of the array

mid= lower of the two middle indices of the array

Initially, we set index to 0 and bot to 1.

The given array contains 10 elements, thus we set top to 10.

Let us write this information down in a trace table.

 Iteration 0 index 0 bot 1 top 10 mid

FIRST ITERATION:

We first assign mid to the lower of the two middle values of the array.

mid=bot+top2=1+102=112=5.5=5

We then note that x<a since Amanda occurs before Jose in the alphabetical ordering. We then assign mid − 1 to top.

top=mid1=51=4

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

 Iteration 0 1 index 0 bot 1 top 10 4 mid 5

SECOND ITERATION:

We first assign mid to the lower of the two middle values of the array

To determine

(b)

Trace the action of the binary search algorithm (Algorithm11.5.1) on the variables index, bot, top, mid, and thegiven values of x for the input array a  = Chia, a  = Doug, a  = Jan, a  = Jim, a  = José, a  = Mary, a  = Rob, a  = Roy, a  = Sue, a  = Usha, where alphabeticalordering is used to compare elements of the array.

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