Linear search in python

Linear search in python







linear search means searching a element in array, search concept is The one element is compares each array index, when the position is founded, return the position of arrar element, like in image-



def LinearSearch(arr,x,n):
for i in range(n):
if arr[i]==x:
return i;
return -1;
arr=[5,3,9,34,56,77];
x=56;
n=len(arr);
obj=LinearSearch(arr,x,n);
if obj==-1:
print('Element is not avaliable');
else:
#retuen index of element
print('Element position is ',obj);
view raw python hosted with ❤ by GitHub