Skip to main content

Linear Search

Definition​

Linear search is a simple searching algorithm that sequentially checks each element in a list until the desired element is found or the end of the list is reached. It is applicable to both ordered and unordered lists

Practice​

linearSearch(list, target):
// Iterate through each element in the list
for index from 0 to length(list)-1:
// Check if the current element matches the target
if list[index] equals target:
// Return the index of the target element
return index
// If target not found, return a failure signal
return -1