levo

Searching and Shortest-Path Algorithms

Comparing linear and binary search

  • 3 things to know
  • Component 1

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.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

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

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

KDW to HAT.
decryptsencryptscompresses

Blank Blitz makes facts automatic

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

AThe two are not the same.
BOpen source refers to the availability of the code.
CMuch open source software is free of charge.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

Backup means the copy of the data.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

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.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

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