An array contains the following elements 13 17 18 26 44 56 8

An array contains the following elements:    13   17   18   26   44   56   88   97. Using the binary search algorithm (p. 607, textbook), trace the steps followed to find 20. At each loop iteration, including the last, show the contents of first, last, and mid. Provide your results in a table format:

Loop #       First     Mid    Last    Compare

…….

Location =__                Found = true (false)

Solution

As you reached the end of the loop, the element is not found in the list.

Loop # First Mid Last Compare
1 0 3 7 20 < 26 Move to left.
2 0 1 2 20 > 17 Move to right.
3 2 2 2 20 > 18 Move to right.
4 3 -- 2 Location = -1, Found = false.
An array contains the following elements: 13 17 18 26 44 56 88 97. Using the binary search algorithm (p. 607, textbook), trace the steps followed to find 20. At

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site