Linear search can be used to search for a desired value in a list. It achieves this by examining each of the elements and comparing it with the search element starting with the first element to the last element in the list until it finds a match.

The steps are:

  1. Examine the first element of the list.
  2. If the first element is equal to the target value, stop.
  3. If the first element is not equal to the target value, check the next element in the list.
  4. Continue steps 1-3 until the element is found or the end of the list is reached.

For example, we can use the linear search algorithm to find the target value 22 in a list. The algorithm iteratively moves through the list until it finds a 22 in the 7th position of the list.


Use linear search to find 23 in the list of numbers on the right. It appears twice. Would linear search stop when it reaches the third element or ninth element of the list?

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?