Seneca

Linear Search

Computer Science: KS3, topic 1.2.9

Linear Search

Linear search is one of the simplest search algorithms.

The concept

The concept

  • You are looking for a specific piece of paper in a stack of papers.
  • One way to find the paper is to start at the top of the stack.
  • Then work down to the bottom.
  • You check each paper on the way.
  • Linear search works in the same way as finding the paper.
In English

In English

  • Check the first item in the dataset.
  • If the first item is what we are looking for, return the first item.
  • Check the second item in the dataset in the same way.
  • Continue for rest of items.
  • We reach the end of the data set.
  • Then the item was not in our data set.
Linear search pseudocode

Linear search pseudocode

Pros and cons of linear search

Pros and cons of linear search

  • Pros:
  • Very easy to implement.
  • Cons:
  • Slow to process long lists.

Test yourself on Linear Search

  • What is the main disadvantage of linear search?

  • Linear Search in English

  • Linear Search Pseudocode

  • Pick the true sentence about linear search.

Practise this topic for free