Big Data EX 3
Big Data EX 3
AIM:
To implement a Python program to perform linear and binary search using Python.
.
ALGORITHM:
CODE:
if arr[mid] == target:
return mid
elif arr[mid] < target:
left = mid + 1
else:
right = mid - 1
return -1
if _name_ == "_main_":
arr = [10, 20, 30, 40, 50, 60, 70, 80, 90]
target = 50
linear_result = linear_search(arr, target)
if linear_result != -1:
print(f"Linear Search: Element {target} found at index {linear_result}.")
else:
print("Linear Search: Element not found.")
OUTPUT:
RESULT:
Thus the program to perform linear and binary search is implemented and the output
is verified successfully.