Binary Search

A searching algorithm that is designed to search from a sorted list.

Idea:

  • Compare the target with the middle most value

  • If not found, eliminate the half where the target cannot exist

Cons/Caveat:

  • The database must be comparable and sortable

Algorithm Demonstration

  • First is a binary search and showing how it’d work

  • Second is a sequential search which is the same as a linear search

Big O Notation: O(logn)O(logn)

We are splitting the dataset continuously into halves until we hit our target or not find our target.

Algorithm

Last updated