DSAverse
Initializing Sorting Algorithms...
Sorting Algorithm
Binary Tree
Graph Traversal
Preparing interactive visualizations for optimal learning experience...
Initializing Sorting Algorithms...
Preparing interactive visualizations for optimal learning experience...
Initializing Sorting Algorithms...
Preparing interactive visualizations for optimal learning experience...
Watch how Linear Search checks each element sequentially until the target is found or the array ends.
Click Start to begin Linear Search visualization
def linear_search(arr, target):
found_indices = []
for i in range(len(arr)):
if arr[i] == target:
found_indices.append(i)
return found_indices if found_indices else -1
# For finding first occurrence only:
def linear_search_first(arr, target):
for i in range(len(arr)):
if arr[i] == target:
return i
return -1