levo

Searching and Shortest-Path Algorithms

Comparing linear and binary search

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

Overview

The two searches set against each other on how they narrow the data, on comparisons needed in the worst case, on memory, and on when the difference is worth anything.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

Compare the linear and binary searches on memory use and on which duplicate they return.

Key term

State the key difference in how linear and binary searches narrow the data.

Key term

Compare the time complexity of the two searches.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    State the key difference in how linear and binary searches narrow the data.

    Model answer

    A linear search removes one item from consideration per comparison. A binary search removes half of the remaining items per comparison.

  2. 2

    Compare the time complexity of the two searches.

    Model answer

    A linear search is O(n) and a binary search is O(log n). The gap widens rapidly as the list grows.

  3. 3

    For a sorted list of 16 items, how many comparisons does each search need in the worst case?

    Model answer

    A linear search needs 16 comparisons in the worst case. A binary search needs only 5, since each comparison leaves at most half of the items.

  4. 4

    Which search is faster on a list of eight items, and does the difference matter?

    Model answer

    A binary search needs at most four comparisons against eight for a linear search. The difference is negligible on such a short list.

  5. 5

    Why can a linear search be quicker overall on a small unsorted list?

    Model answer

    Sorting the list first costs more than the few comparisons a linear search would need. The saving from a binary search appears only on larger data.

  6. 6

    Which search would you use on a telephone directory, and why?

    Model answer

    A binary search suits a directory because the entries are already in alphabetical order. Very few comparisons are needed even for millions of names.

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.

Data Structures: Arrays, Records and Hash Tables
Stacks, Queues, Linked Lists and Trees
Boolean Logic and Simplification
Algorithms, Pseudo-Code and Programming Constructs

Cram the night before, weakest topic first

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

KDW to HAT.
decryptsencryptscompresses

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.

Backup means the copy of the data.
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 Shortest-Path 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.