- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference Between Linear Search and Binary Search
In this post, we will understand the difference between Linear Search and Binary Search.
Linear Search
It searches through the array/list from the beginning to the end.
Every element in the array/list is compared to the element that needs to be searched.
It goes till the end of the list.
If the element is found, a message is returned, with the index.
If the element is not found, relevant message is returned.
The elements don't need to be arranged in a specific/sorted order.
It can be implemented on any linear data structure like an array, linked list.
It is based on sequential approach.
It is preferable to use it with small-sized data sets.
It is less efficient when the size of the array/list is large.
The worst- case complexity to find an element is O9n) where ‘n’ is the number of elements.
The best-case complexity to find an element is O(1).
It can be used with single and multidimensional array.
Binary Search
The array to perform binary search on, should be sorted.
The position of the element to be searched is found by first finding the middle element.
The middle element is the average of the first index and last index of the array/list.
It can only be used on data structures that have two-way traversal.
It is based on divide and conquer approach.
It is used with large sized datasets.
It is more efficient on large datasets.
The worst-case complexity is O(log2n), where ‘n’ is size of the array.
The best-case complexity to find an element is O(1).
It can be implemented on a multidimensional array only.
- Related Articles
- Difference between Binary Tree and Binary Search Tree
- Difference between Organic Search and Paid Search
- Linear Search
- Difference Between Informed and Uninformed Search
- Binary Search Tree - Search and Insertion Operations in C++
- Difference Between Search Engine and Web Browser
- Linear search in Java.
- Binary Search\n
- What is the difference between a search engine friendly and search engine optimised website?
- Linear Search in Python Program
- Python Program for Linear Search
- Implementing Linear Search in JavaScript
- Binary Search in C++
- Binary search in Java.
- Optimal Binary Search Tree
