इस लेख में, हम लीनियर सर्च और पायथन 3.x में इसके कार्यान्वयन के बारे में जानेंगे। या पहले।
एल्गोरिदम
Start from the leftmost element of given arr[] and one by one compare element x with each element of arr[] If x matches with any of the element, return the index value. If x doesn’t match with any of elements in arr[] , return -1 or element not found.
आइए अब दिए गए दृष्टिकोण का दृश्य प्रतिनिधित्व देखें -

उदाहरण
def linearsearch(arr, x):
for i in range(len(arr)):
if arr[i] == x:
return i
return -1
arr = ['t','u','t','o','r','i','a','l']
x = 'a'
print("element found at index "+str(linearsearch(arr,x))) आउटपुट
element found at index 6
चरों का दायरा चित्र में दिखाया गया है -

निष्कर्ष
इस लेख में, हमने Python3.x में रैखिक खोज के तंत्र के बारे में सीखा। या पहले।