[try Beta version]
Not logged in

 
Binary search array

Apr 14, 2015 at 9:57pm
Does anyone know if a good tutorial or youtube video to explain a binary search in an array?
Apr 14, 2015 at 10:02pm
1. User provides an array, the search target, and the range to search in.
2. If lower bound of range is higher than upper bound of range, return -1 (target not in array).
3. Find the midpoint of the range.
4. If value at midpoint is equal to search target, return midpoint.
5. If value at midpoint is lower than target, set the lower bound of range to midpoint + 1.
6. If value at midpoint is higher than target, set the upper bound of range to midpoint - 1.
7. Go to step 2.

NOTE: This assumes the array is sorted into ascending order.
Last edited on Apr 15, 2015 at 1:31am
Apr 14, 2015 at 10:04pm
I guess I should have asked for an example of how it is coded.
Apr 14, 2015 at 10:08pm
http://video.franklin.edu/Franklin/Math/170/common/mod01/binarySearchAlg.html

Try not to make posts that you could easily solve yourself by visiting google.
Topic archived. No new replies allowed.