Discrete Mathematics and Its Applications, Seventh Edition

Published by McGraw-Hill Education
ISBN 10: 0073383090
ISBN 13: 978-0-07338-309-5

Chapter 3 - Section 3.1 - Algorithms - Exercises - Page 203: 26

Answer

To make the appropriate change, we add the following statement anywhere within the while loop: if $x=a_m$ then return $m$ No other changes are needed to Algorithm $3$.

Work Step by Step

This was referred to in a previous answer dealing with binary search. Here, we are checking at each level if our value is equal to the mid-value. It is a slight change but it helps make the algorithm more efficient. For example, in exercise 13, we found the target value yet the algorithm did not terminate and continued iterating. While the few extra steps saved for every iteration of the algorithm may not seem much, when there are millions and millions of search operations happening, that would equal a lot of steps in total!
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.