Linear search
Linear search: check every item from the start until you find it.
- Works on any list, sorted or not.
- Simple.
- Slow on long lists: a million items may need a million checks.
Topic 12 Searching and sorting
KS3 Computing · Searching finds an item. Sorting puts items in order. Some algorithms are hugely faster than others on big lists, and the difference grows as the list grows.
Topic 13 Programming basics
KS3 Computing · A program stores information in variables, works on it with operators, and controls the order with sequence, selection and iteration. Examples are in Python, with Scratch alongside for Year 7.
Programming Computational ThinkingCambridge Lower Secondary Computing 0860
Say each word, then read what it means. Every one is in the glossary too.
Read it here, or open the study page below to go one step at a time with things to try.
Linear search: check every item from the start until you find it.
Binary search needs a sorted list. Like a dictionary: open in the middle, throw away the wrong half, repeat.
| Items | Linear (worst) | Binary (worst) |
|---|---|---|
| 10 | 10 | 4 |
| 1,000 | 1,000 | 10 |
| 1,000,000 | 1,000,000 | 20 |
Why so fast? Each check halves the list. Doubling the list only adds one check. (2¹⁰ = 1,024 and 2²⁰ ≈ 1 million.)
| Scratch | Python |
|---|---|
| say [Hello] | print("Hello") |
| ask [Name?] and wait | name = input("Name? ") |
| set [score] to 0 | score = 0 |
| change [score] by 1 | score = score + 1 |
| if … then … else | if …: / else: |
| repeat 10 | for i in range(10): |
| repeat until … | while not …: |
| forever | while True: |
| pick random 1 to 10 | random.randint(1, 10) |
Open the study page and go one step at a time.
Searching finds an item. Sorting puts items in order. Some algorithms are hugely faster than others on big lists.
Topic 13 · Year 8A program stores information in variables, works on it with operators, and controls the order with sequence, selection and iteration. Examples are in Python.
One question at a time. The reason shows after each answer.