Linear Search, also known as sequential search, is the simplest searching algorithm. It checks every element in the list sequentially until the desired element is found or the list ends.
Pseudocode:
procedure linear_search(arr, x)
for i = 0 to length(arr) - 1 do
if arr[i] = x then
return i
return -1
def linear_search(arr, target):
for i in range(len(arr)):
if arr[i] == target:
return i
return -1
# Usage Example
arr = [10, 23, 45, 70, 11, 15]
target = 70
result = linear_search(arr, target)
if result != -1:
print(f"Element {target} found at index {result}")
else:
print(f"Element {target} not found in the list")