LINEAR and BINARY SEARCH
LINEAR and BINARY SEARCH
The computer has to look through every item in the list which a little bit
time taking but the easiest to find a search term.
A faster way to search a list is called Binary search. binary means “made of
two parts” or “divided into two”.
HOW IT WORKS?
1. Sort the list into order.
2. Find the midpoint of the list.
3. Compare the search term to the midpoint. Is it higher or lower?
4. Split the list in half and keep the higher or lower half
5. Keeps splitting the list in half only one item.
ATTENTION!!!
You can only use the binary search when the list you have is sorted.
RESULT!!!
If the search term is founded it displays you have found it and if not found
it displays the search term is not in the list.
LINEAR BINARY
Can be used on both sorted and Can only be used if the list is sorted
unsorted lists
Less efficient for large data sets More efficient to large data sets