TYLOGIX DownloadsBack to Tylogix Home Page
The BINSEARCH Binary Array Search Example
Download BINSEARCH NOW : BINSEARCH
The binary search
is designed to minimize the number of arrary searches.
It assumes a sorted array.
If you have a 100
element array, the average number of comparisons to find an
element with the LOKUP operation is 50 (It takes 100 comparisons to determine
a 'not found' condition). A binary search can cut this to 7 comparisons.
The performance difference
increases dramatically as the size of the array increases.
For example, on a 9999 element array, the average comparisons for LOKUP is 4999
(9999 comparisons to determine a 'not found' condition). A binary search will take only
While there is more
overhead to perform a binary search the major performance
consideration is the number of comparisons made.
This program is a
sample only. It first loads an array of 9999 elements with numbers
incremented by 3. It then provides a screen for the user to verify the searches, and
how many comparisons were made to find any given element.
This utility is aimed
at programmers. The actual search is done in two subroutines
that can be copied and recycled in an other program.