Skip to content

Files

Latest commit

02825e3 · Mar 25, 2017

History

History
This branch is up to date with Algorithm-archive/Learn-Data_Structure-Algorithm-by-Python:master.

README.md

Linear Search

Linear search is a very simple search algorithm. In this type of search, a sequential search is made over all items one by one. Every item is checked and if a match is found then that particular item is returned, otherwise the search continues till the end of the data collection.

Linear Search

Python Implementation

Though it is very easy in python to check for an item's existence in a list by:

item in list

and finding an item's index by:

list.index(item)

but sometimes you might need to do some customization on the searching algorithm. Like- 'finding the last occurrence of the item in the list' etc. This linear search implementation will help you to do that.

Complexity Analysis

  • Worst Case - O(n)
  • Best Case - O(1)
  • Average Case - O(n)

More on this topic