Introduction


Linear Search Technique: Linear Search is a simple search algorithm that checks each element in a list, one at a time, to find the target element.
It does not require the list to be sorted and works on any dataset.

Examine each element until the target is found.

How can we search for an element?

  • Start at the first element of the array.
  • Compare each element with the target element.
  • If a match is found, return the index of the matching element.
  • If the entire array is traversed without finding the target, return "Not Found."

Important Observations

  • The algorithm does not rely on the dataset being sorted.
  • The search process stops as soon as the target element is found.
  • In the worst case, the algorithm examines all elements.

Key Characteristics:

  • Works on both sorted and unsorted datasets.
  • Simple to implement.

Advantages:

  • No preprocessing or sorting required.
  • Applicable to small or unsorted datasets.
  • Stops immediately when the target element is found.

Disadvantages:

  • Not efficient for large datasets.
  • Worst-case time complexity is (O(n)).

Time Complexity:

  • Best Case: (O(1)) (target found at the first element).
  • Average Case: (O(n)).
  • Worst Case: (O(n)).