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

  1. Start from the first element of the array.
  2. Compare the current element with the target value.
  3. If they match, return the index.
  4. If not, move to the next element.
  5. 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)