levo

Searching and Sorting Algorithms

Linear search and binary search

  • 3 things to know
  • Papers 1 and 2
Start revising · £5/month

Overview

How linear and binary searches work, worked binary searches, the number of comparisons each needs, and when each suits the data.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

Search the sorted list 3, 8, 12, 19, 25, 31, 40 for 25 using a binary search

Key term

Search the sorted list 3, 8, 12, 19, 25, 31, 40 for 10 using a binary search

Evaluation

Give one advantage and one disadvantage of a binary search

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 the list in turn, starting at the first. The search stops when the item is found or the end of the list is reached.

  2. 2

    Give one advantage and one disadvantage of a linear search.

    Model answer

    A linear search works on an unsorted list. A linear search is slow for a long list, because every item may need to be checked.

  3. 3

    How does a binary search work?

    Model answer

    A binary search looks at the middle item of a sorted list. Half of the list is discarded each time, until the item is found or no items remain.

  4. 4

    What must be true of a list before a binary search can be used?

    Model answer

    The list must be sorted into order. A binary search relies on knowing which half could hold the item.

  5. 5

    Give one advantage and one disadvantage of a binary search.

    Model answer

    A binary search is much faster than a linear search on a long list. The list must be sorted first, which takes time.

  6. 6

    Search the sorted list 3, 8, 12, 19, 25, 31, 40 for 25 using a binary search.

    Model answer

    The sorted list 3, 8, 12, 19, 25, 31, 40 has 19 as its middle item. The target 25 is larger, so 19 and the left half are discarded. The middle of 25, 31, 40 is 31, and 25 is smaller, so 31 and 40 are discarded. The item 25 is checked next and found.

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
Searching and Sorting Algorithms
Decomposition and Abstraction
Developing and Testing Code

Cram the night before, weakest topic first

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

Denary is a base system.
1028

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.

Nibble means a group of four bits.
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 Searching and Sorting 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.