levo

Recursion, Sorting and Searching

Searching and shortest-path algorithms

  • 3 things to know
  • A2 Unit 3

Overview

Recall questions on the complexity of linear and binary search and why, the comparisons needed on a million items, when linear beats binary, why binary needs an array, what Dijkstra's algorithm records and why it can finalise the smallest distance, negative weights, a worked shortest route, and A*.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

How does the A* algorithm differ from Dijkstra's algorithm?

Key term

State the complexity of a binary search and explain why it has that complexity.

Key term

State the greatest number of comparisons a binary search makes on a sorted list of 1,000,000 items.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    State the complexity of a linear search and explain why it has that complexity.

    Model answer

    A linear search is O(n), because in the worst case every one of the n items has to be examined before the answer is known.

  2. 2

    State the complexity of a binary search and explain why it has that complexity.

    Model answer

    A binary search is O(log n), because every comparison discards half of the items still under consideration.

  3. 3

    State the greatest number of comparisons a binary search makes on a sorted list of 1,000,000 items.

    Model answer

    2¹⁹ is 524,288 and 2²⁰ is 1,048,576, so at most 20 comparisons are needed.

  4. 4

    How many further comparisons does a binary search need when the list it is given is doubled in length?

    Model answer

    Just one more, because that single extra comparison halves the doubled list back to its original length.

  5. 5

    Under what conditions does a linear search beat a binary search?

    Model answer

    A linear search wins on a very short list, on a list that is not in order, and wherever the cost of sorting the list first would outweigh the saving.

  6. 6

    Why must a binary search be given a list held in an array rather than in a linked list?

    Model answer

    A binary search has to jump straight to the midpoint, and only an array allows a position to be reached by calculation rather than by following pointers from the start.

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.

Hardware: Architecture, Memory and Storage
Networks and Data Transmission
Logic Gates and Boolean Algebra
Data Representation and Data Types

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.

Fetch, , execute.
decodecompilestore

Blank Blitz makes facts automatic

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

AEncryption is reversible.
BThe stored form could be decrypted.
CA hash cannot be reversed.

Build It gets the exam shape right

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

A bit is a single binary digit.
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 Recursion, Sorting and Searching, 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.