Related Topics

Data Structure
def linear_search(arr, target):
for i in range(len(arr)):
if arr[i] == target:
return i
return -1 # target not found
In this implementation, arr
is the collection being searched and target
is the element being searched for. The function iterates over each element in arr
and checks if it matches target
. If a match is found, the index of the matching element is returned. If no match is found, the function returns -1 to indicate that the target element is not present in the collection.




Popular Category
Topics for You
Go through our study material. Your Job is awaiting.