pyrhon program for linear search
Answers
Answered by
0
Answer:
def search(arr, x):
for i in range(len(arr)):
if arr[i] == x:
return i
return -1
Explanation:
# Searching an element in a list/array in python
# can be simply done using \'in\' operator
# Example:
# if x in arr:
# print arr.index(x)
# If you want to implement Linear Search in python
# Linearly search x in arr[]
# If x is present then return its location
# else return -1
Similar questions
History,
5 months ago
History,
5 months ago
Math,
11 months ago
English,
11 months ago
Computer Science,
1 year ago