Linear or Sequential Search Algorithm

Linear or sequential search algorithm is a method for finding a target value within a list.

It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched.

For a list with n items, the best case is when the value is equal to the first element of the list, in which case only one comparison is needed.

The worst case is when the value is not in the list (or occurs only once at the end of the list), in which case n comparisons are needed.

Binary Search
Linear or Sequential Search Explanation
Performance
  • Worst-case performance :- O(n)
  • Best-case performance :- O(1)
  • Average performance :- O(n)
  • Worst-case space complexity :- O(1) iterative
Java Program of Linear Search Algorithm

Output

Required key:- 2 found at index:- 3 Key 18 not found

Also Read Binary Search Algorithm

Some theory part of this article uses material from the Wikipedia article “Linear search”, which is released under the CC BY-SA 3.0.

It's good to share...Share on FacebookTweet about this on TwitterShare on LinkedInPin on PinterestShare on Google+Email this to someone

Leave a Reply

Your email address will not be published. Required fields are marked *