Search Algorithms

Homepage

BINARY SEARCH

Binary Search

Binary search algorithm process:

  1. Find the middle item in the list: (n+1) / 2
  2. If this is your item, stop the search.
  3. If not, identify whether the item you are looking for is greater than or less than the middle item. If the item is greater than the middle item, get rid of the first half of the list. Do the opposite if the item is less than the middle item.
  4. Repeat steps 1-3 with your new list. Keep repeating until you find the item you are looking for.

Key characteristics:

  • Only works in ordered lists
  • Is generally quite fast

DIFFERENCES

Binary VS Linear
  • Linear searches can be used on any kind of list.
  • Linear searches are much simplier than binary but not as efficient as binary.
  • For smaller, ordered lists, both types of searches have similiar run time so there will not be much of a difference between each of them.
  • For larger, ordered lists, a binary search will usually be far quicker than a linear search.

LINEAR SEARCH

Linear Search

Linear search algorithm process:

  1. Look at the first item.
  2. If this is your item, stop the search.
  3. If not, look at the next item in the list.
  4. Repeat steps 2-3 until you have found the item you are looking for.

Key characteristics:

  • Can be used on both unordered or ordered lists.
  • Is generally quite slow.