levo

Searching and Shortest-Path Algorithms

Linear search

  • 3 things to know
  • Component 1

Overview

How a linear search works, main advantage of a linear search and time complexity of a linear search.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What does each of the linear and binary searches assume about order, and when is the linear search right?

Key term

Describe how a linear search works.

Evaluation

What is the main advantage of a linear search?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    Describe how a linear search works.

    Model answer

    A linear search examines each item in turn from the start of the list. The search stops when the target is found or the end of the list is reached.

  2. 2

    What is the main advantage of a linear search?

    Model answer

    A linear search needs no ordering of the data, so it works on any list. The algorithm is also very simple to write and to check.

  3. 3

    State the worst case number of comparisons a linear search makes on a list of n items.

    Model answer

    The worst case is n comparisons, which happens when the target is last or absent. A list of twice the length gives twice the worst case.

  4. 4

    How many comparisons does a linear search make on average when the item is present?

    Model answer

    The average is about half the list, or (n + 1) ÷ 2 comparisons. The figure is roughly 100 for a list of 200 items.

  5. 5

    A linear search looks for 23 in the list 8, 15, 4, 23, 42, 7. How many comparisons are made?

    Model answer

    Four comparisons are made because 23 sits in the fourth position. The search stops as soon as the item is found.

  6. 6

    A linear search looks for 30 in the list 8, 15, 4, 23, 42, 7. How many comparisons are made?

    Model answer

    Six comparisons are made because every item must be checked. The search then reports that 30 is not in the list.

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.