Computer Science Canada help RE: Binary searches |
Author: | drewst18 [ Tue Nov 30, 2004 1:21 pm ] |
Post subject: | help RE: Binary searches |
We have a program to write, using binary search. I have no idea how to do this(nobody in the class does). Can someone help by teaching us or doing a quick search |
Author: | bugzpodder [ Tue Nov 30, 2004 1:27 pm ] |
Post subject: | |
Definition: Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty. |
Author: | wtd [ Tue Nov 30, 2004 3:18 pm ] |
Post subject: | |
bugzpodder wrote: Definition: Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.
Or in other words, the old game of guess the number. Let's say I tell you to guess a number between 1 and 10. You get three guesses. The answer: 3 First guess: 5 Too high! Next Guess: 2 Too low! Final guess: 3 (the only other option is 4) Correct! |