CIS3355:
Business Data Structures |
This value is greater than 18, therefore 23 becomes the new "hi" point and 17 becomes the new "lo" point for our search.
Success at last! The new mid-point contains the value that we are searching for. If at any point during our search process the value of our "lo" point becomes greater than the value of our "hi" point the search process is halted without a result. The following Table allows you to compare the two between the sequential search and the binary search.
Table 9.3 The fundamental idea of binary search is surprisingly simple 1. You have a sorted array 2. You look at the middle element 3. This element tells you if the element you're looking for is in the top or bottom half, and then you take that half. 4. Repeat this process until you find the element you are searching for. Remember that as the number of elements to be searched continue to increase so will the number of comparisons needed. For more information visit the following websites: |