Linear Searching
12
24
2
20
7
69
23
18
13
90
4
17
About algorithm
Explanation
Linear Search is the simplest method to find an element in a list. It sequentially checks each element until the target is found or the end of the list is reached.
Steps
- Start from the first element of the array.
- Compare the current element with the target value.
- If they match, return the index.
- If not, move to the next element.
- Repeat until the target is found or the end of the array is reached.
Pseudocode
linearSearch(arr, target): for i from 0 to len(arr) - 1: if arr[i] == target: return i return -1
Complexity
Time: O(n)
Space: O(1)