Linear Search Algorithm variations in Java

Linear Search is a brute force approach or sequential approach for finding value in a list of values. Even though, it is a single algorithm, can be written in many ways to simplify algorithmic time complexity based on input values. Linear Search can be a Brute force solution, it’s worst cost is proportional to the number of elements in the list. Linear search with sorted array as an input, we can improve the complexity by checking condition that the element is more than that it is being compared with, we can just ignore searching in the later part of the array. Some times Recursion is easy to code, Linear search can be written in a recursive fashion.

Here is the implementation for Linear Search Algorithm variations in Java

1.Linear Search (Bruteforce)

Java

2.Linear Search with Recursion

Java

A sample Test client for above two algorithms

Java

3.Sorted Array Linear Search

SortedArrayLinearSearch.java

Leave a Comment