The Binary Search algorithm works by testing a mid-point, then eliminating half of the list. In this exercise, you are going to take our binary search algorithm and add print statements so that you can track how the search executes. Inside of the recursive binary search function, add print statements to print out the starting, ending, and midpoint values each time. Then as you test a value, print out the results, either too high, too low, or a match.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question
100%

The Binary Search algorithm works by testing a mid-point, then eliminating half of the list.

In this exercise, you are going to take our binary search algorithm and add print statements so that you can track how the search executes.

Inside of the recursive binary search function, add print statements to print out the starting, ending, and midpoint values each time.

Then as you test a value, print out the results, either too high, too low, or a match.

Sample Output

Starting value: 0 Ending value: 9 Testing midpoint value: 4 Too high! Starting value: 0 Ending value: 3 Testing midpoint value: 1 Too low! Starting value: 2 Ending value: 3 Testing midpoint value: 2 Match!

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Merge Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning