Explore BrainMass

binary search

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

What is a binary search, and how does it work?

© BrainMass Inc. brainmass.com October 24, 2018, 5:08 pm ad1c9bdddf

Solution Preview

Binary Search is arguably one of the most useful algorithms you will come across. It accepts a sorted list of numbers, a single integer value x as input, and returns the xth greatest number in the list.

For example, consider the following sorted list of ten integers:
1, 2, 3, 4, 6, 8, 9, 10, 12, 15

Say that we are looking to see if 12 is in the list. First, look at the middle value in the list. We can find this by looking at the indices of the first and last elements. Since we have a list of ten numbers, we look for the element in position (1+10)/2 = 5.5. In our list, this is the number 6. We ...

Solution Summary

This job defines a binary search.

See Also This Related BrainMass Solution

Detailed Comparision of Linear and Binary Searches on a List

Suppose that you have a dictionary whose words are not sorted in alphabetical order. As a function of the number, n of words, what is the efficiency of searching for a particular word in this dictionary ?

Do the same for dictionary whose words are sorted alphabetically. Compare results.

View Full Posting Details