Prerequisite:

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

- The worst case complexity is O(n), sometimes known an O(n) search
- 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.

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

**Important Differences**

- Input data needs to be sorted in Binary Search and not in Linear Search
- Linear search does the sequential access whereas Binary search access data randomly.
- Time complexity of linear search -O(n) , Binary search has time complexity O(log n).
- Linear search performs equality comparisons and Binary search performs ordering comparisons

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**

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.

## Recommended Posts:

- Meta Binary Search | One-Sided Binary Search
- C/C++ Program for Linear Search
- Java Program for Linear Search
- Linear search using Multi-threading
- Sentinel Linear Search
- Linear Search
- Improving Linear Search Technique
- Interpolation search vs Binary search
- Why is Binary Search preferred over Ternary Search?
- K'th Smallest/Largest Element in Unsorted Array | Set 2 (Expected Linear Time)
- K'th Smallest/Largest Element in Unsorted Array | Set 2 (Expected Linear Time)
- K'th Smallest/Largest Element in Unsorted Array | Set 3 (Worst Case Linear Time)
- Median of two sorted arrays of different sizes | Set 1 (Linear)
- Sublist Search (Search a linked list in another list)
- Repeatedly search an element by doubling it after every successful search
- Best First Search (Informed Search)
- The Ubiquitous Binary Search | Set 1
- Unbounded Binary Search Example (Find the point where a monotonically increasing function becomes positive first time)
- A Problem in Many Binary Search Implementations
- Longest Common Prefix using Binary Search