Open In App

What is Linear Search?

Improve
Improve
Like Article
Like
Save
Share
Report

Linear search is defined as the searching algorithm where the list or data set is traversed from one end to find the desired value.

Linear search method

Linear search method 

Linear search works by sequentially checking each element in the list until the desired value is found or the end of the list is reached. 

Properties of Linear search  :

  • Time Complexity: The worst case time complexity of linear search is o(n), where n is the size of the array.
  • Space Complexity:  Linear search requires a constant amount of memory to run.
  • Efficiency: Linear search is effeicient for small datasets but becomes inefficient for larger datasets. In practice, linear search is often used as a subroutine in more complex algorithms.
  • Implementation: Linear search can be easily implemented using a loop, with each iteration comparing the target value to the current element of the array.

Application of Linear Search :

Linear search has several practical applications in computer science and beyond. Here are some examples:

  • Phonebook Search: Linear search can be used to search through a phonebook to find a person’s name, given their phone number. 
  • Spell Checkers:  The algorithm compares each word in the document to a dictionary of correctly spelled words until a match is found.
  • Finding Minimum and Maximum Values: Linear search can be used to find the minimum and maximum values in an array or list. 
  • Searching through unsorted data: Linear search is useful for searching through unsorted data.

Advantages of Linear Search :

Here are some advantages of using linear search :

  • Simplicity: Linear search is a very simple algorithm to understand and implement.
  • Works with unsorted data:  Linear search works well with unsorted data. It does not require any pre-processing or sorting of the data before performing the search.
  • Low memory usage: Linear search only requires a small amount of memory to store the index of the current element being searched.
  • Easy to debug: Because linear search is a simple algorithm, it is easy to debug and troubleshoot any issues that may arise.

Disadvantages of Linear search : 

  • Inefficient for large datasets: As the size of the dataset grows, the time taken by linear search also increases proportionally. 
  • Limited applicability: Linear search is only suitable for datasets that are not too large or not too complex.
  • No early termination: Linear search does not have a mechanism to terminate early once the target element is found.
  • Inefficient for sorted data: When the data is already sorted, linear search is not efficient because it needs to check each element one by one, even if it has already passed the target element.

What else can you read?


Last Updated : 13 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads