May 12, 2021, 8:47 p.m.
Linear Search is a very simple method for searching an array for a particular value. It works by comparing the value to be searched with every element of array one by one in a sequence until a match is found.
Linear search is mostly used to search an unordered list of elements.
Linear Search is a very simple method for searching an array for a particular value. It works by comparing the value to be searched with every element of array one by one in a sequence until a match is found.
Linear search is mostly used to search an unordered list of elements.
#Python
number=[5, 6, 8, 15, 30, 60, 69, 33, 24, 96, 35, 42]
n=int(input())
count=-1
for i in number:
if i==n:
count+=1
print('Number exists in the list')
if count==-1:
print('Number does not exist in the list')
The linear search is simple - It is very easy to understand and implement.
It does not require the data in the array to stored in any particular order.
The linear search is inefficient- If an array contains 2000 elements then algo will have to look at all the elements in order to find a value in the last element.
Read about Binary Search