3. WHAT IS A LINEAR SEARCH?
A linear search is a sequential search that
sequentially search a target element in a
list or an array.
Elements may be sorted or unsorted.
The target element is compared with each
element in the list or array and stops
when either the value is found or the end
of array is encountered.
[1][2]
4. 45 36 20 68 70
Exampleof a linearsearch:-
Suppose the element that we want to
search is 68.
1 2 3 4 5
Target element = 68
5. 45 36 20 68 70
If the target element is not found at the
first search then the searching will be
continued to the next location.
1 2 3 4 5
Target element = 68
6. 45 36 20 68 70
1 2 3 4 5
Target element = 68
Again the searching will be continued
to the next location as the element is
not found yet.
7. 45 36 20 68 70
1 2 3 4 5
Here, the target element is found at the
location= 4.
Searching is successful and further searching
is not needed.
Target element = 68