levo

Algorithms

Linear search and binary search

  • 3 things to know
  • Paper 1
Start revising · £5/month

Overview

How linear and binary searches work, why a binary search needs a sorted list, choosing the middle item, traced searches through short lists, worst cases, and when each search is the better choice.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Process

How does a binary search work?

Process

How does a linear search work?

Key term

Does a linear search need the list to be sorted?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    How does a linear search work?

    Model answer

    A linear search checks each item in a list in turn, starting with the first. The search stops when the item is found or when the list runs out.

  2. 2

    Does a linear search need the list to be sorted?

    Model answer

    A linear search works on a sorted or an unsorted list. The search simply compares every item with the target until it finds a match.

  3. 3

    A linear search looks for 9 in the list [4, 7, 9, 2]. Which items are compared?

    Model answer

    The search compares 4, then 7, then 9. The item is found on the third comparison, so 2 is never checked.

  4. 4

    A linear search looks for 6 in the list [4, 7, 9, 2]. How many comparisons are made?

    Model answer

    The search makes four comparisons, one with every item. The value 6 is not in the list, so the search reports that it was not found.

  5. 5

    What is the worst case for a linear search?

    Model answer

    The worst case is when the target is the last item or is not in the list. Every item must then be compared.

  6. 6

    How does a binary search work?

    Model answer

    A binary search compares the target with the middle item of a sorted list. The half that cannot contain the target is discarded. The search repeats on the remaining half until the item is found or none are left.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Algorithms
Programming
Data Representation
Computer Systems

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

The table one extra row.
gainslosescopies

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

ASC means sorting from smallest to largest, or A to Z.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Algorithms, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.