Binary Search: How Facebook, Google, Amazon,… search from billions of records

Binary search’s are one of the most common and efficient ways to search through big lists of data

Linear Search and Binary Search

Linear Search

from geeksforgeeks
  1. The elements are in random order
  2. Linear Search looks through items until it finds the searched value.
  3. Worst case time complexity: 0(n)
  4. Scan one item at a time
  5. Single and multi dimensional array is sorted used

Binary Search

  1. The elements are sorted order
  2. Binary Search finds the middle element of the array. Checks that middle value is greater or lower than the search value. If it is smaller, it gets the left side of the array and finds the middle element of that part. If it is greater, gets the right part of the array. We continue this process until the element is found. Or if there is no value in the array finishes the search.
  3. worst case time complexity: 0(log n)
  4. Scan many items at a time
  5. only single dimensional array is sorted used

Which kind of data can we use binary search for ?

  1. Your data must be comparable (e.g, 1 < 5 or A < C)
  2. Your data must be sorted (e.g, 1,2,3,4,5 or A,C,F,H)

A nature, universe, science, music, love lover

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami