What is it?
The process of sequentially checking each value in the list until the target value is found.
A Linear Search scans the elements on at a time, without skipping any element. The array does not need to be in order for the algorithm to be implemented.
<--------
Displays the process of linear search by sequentially going through each element in order to find the target value which is 33.
The target value is ‘J,’ which means that we have to go through each element one by one to find ‘J.’
The Linear Search algorithm has a variable, 'i,' which is set to 1, then shows if 'i' > n (desired value), skip to print element "not found." Though, if A[i] = x, skip to Print element, "x Found at index i," then exit. If step 2 and step 3,
Advantage
Very simple.
Linear search does not require any partitioning.
Does not require the array to be in order.
Disadvantage
Linear search is inefficient.
<------- Example of a linear search, finding the value 5 by sequentially searching through each item in the array.