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

# Trace the modified binary search algorithm for the same input as was used in Example 11.5.1.

To determine

(a)

Trace the modified binary search algorithm for the same input as was used in Example 11.5.1.

Explanation

Given information:

modify the binary search algorithm (Algorithm 11.5.1) to take the upper of the two middle array elements in case the input array has even length. In other words, in Algorithm11.5.1 replace

mid:=bot+top2 with mid:=bot+top2.

Calculation:

a=Anna=Dawna=Erika=Gaila=Juana=Matta=Maxa=Rita

a=Tsujia=Tuen

x= Max

INITIAL ASSIGNMENTS:

bot= bottom index of the arraytop= top index of the arraymid= lower of the two middle indices of the array

Initially, we set index to 0 and bot to1.

The given array contains 10 elements, thus we set up 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 upper of the two middle values of the array.

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

We then note that x>a since Max occurs after Matt in the alphabetical ordering. We then assign mid + 1 to bot.

top=mid+1=6+1=7

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

 Iteration 0 1 index 0 bot 1 7 top 10 mid 6

SECOND ITERATION:

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

mid=bot+top2=7+102=172=8

To determine

(b)

Trace the modified binary search algorithm for the same input as was used in Example 11.5.1.

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