Linear Search vs Binary Search

Prerequisite:

A linear search scans one item at a time, without jumping to any item .

  1. The worst case complexity is  O(n), sometimes known an O(n) search
  2. Time taken to search elements keep increasing as the number of elements are increased.

A binary search however, cut down your search to half as soon as you find middle of a sorted list.

  1. The middle element is looked to check if it is greater than or less than the value to be searched.
  2. Accordingly, search is done to either half of the given list

Important Differences

Let us look at an example to compare the two:

Linear Search to find the element “J” in a given sorted list from A-X

Binary Search to find the element “J” in a given sorted list from A-X

 

You may also see

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

Article Tags :
Practice Tags :