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: 28

Answer

procedure quaternary search$(x: $ an integer $a_1, a_2, ... , a_n: $ list of integers$)$ $i:= 1$ $m := n$ while $i

Work Step by Step

This algorithm is an extension of the binary search to Quaternary search. It proceeds as follows: First it splits the list into four subsets by defining five indices, at the beginning, after a quarter, after two quarters, after three quarters. and the end. Note how we use the floor function to get integer indices. After this, we try to place our $x$ value in one of these intervals. Depending on which conditional is true, we modify the endpoints of the interval. Notice that with each step, the range should be getting decreased by a fourth. Finally, our algorithm terminates when $i\ge j$ indicating that we have only one element in our array. We check if this element is equal to the target and return the index if it's the required result, $0$ otherwise.
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.