Edexcel IGCSE Computer Science 4CP0
Algorithms
Searching and Sorting Algorithms
Decomposition and Abstraction
Developing and Testing Code
Programming Constructs and Operators
Data Types and Data Structures
Input, Output and Validation
Data Representation
Data Storage and Compression
Encryption
Hardware and the CPU
Software
Programming Languages and Translators
Networks
Network Security
The Internet and the World Wide Web
Emerging Trends, Issues and Impact
Searching and Sorting Algorithms
Linear search and binary search
- 3 things to know
- Papers 1 and 2
Overview
How linear and binary searches work, worked binary searches, the number of comparisons each needs, and when each suits the data.
What you need to know
Answer each one before you reveal it.
Search the sorted list 3, 8, 12, 19, 25, 31, 40 for 10 using a binary search
Give one advantage and one disadvantage of a binary search
Questions from this subtopic
Each one with the model answer underneath.
- 1
How does a linear search work?
Model answer
A linear search checks each item in the list in turn, starting at the first. The search stops when the item is found or the end of the list is reached.
- 2
Give one advantage and one disadvantage of a linear search.
Model answer
A linear search works on an unsorted list. A linear search is slow for a long list, because every item may need to be checked.
- 3
How does a binary search work?
Model answer
A binary search looks at the middle item of a sorted list. Half of the list is discarded each time, until the item is found or no items remain.
- 4
What must be true of a list before a binary search can be used?
Model answer
The list must be sorted into order. A binary search relies on knowing which half could hold the item.
- 5
Give one advantage and one disadvantage of a binary search.
Model answer
A binary search is much faster than a linear search on a long list. The list must be sorted first, which takes time.
- 6
Search the sorted list 3, 8, 12, 19, 25, 31, 40 for 25 using a binary search.
Model answer
The sorted list 3, 8, 12, 19, 25, 31, 40 has 19 as its middle item. The target 25 is larger, so 19 and the left half are discarded. The middle of 25, 31, 40 is 31, and 25 is smaller, so 31 and 40 are discarded. The item 25 is checked next and found.
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.
Every question in Searching and Sorting 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.