Explain how a linear search technique is used to search for an element.
Suppose that ARR is an array having N elements. ITEM is the value to be searched. Then we have the following cases:
Case 1: Unsorted List – The ITEM is compared with every element of the array. If the element is found, then no further comparison is required. If all the elements are compared and checked, then the ITEM is not found.
Case 2: Sorted List – The ITEM is greater than the first element and smaller than the last element of the list, so searching is performed by comparing each element in the list with ITEM; otherwise, ITEM is reported as “Not Found.”