Searching: Edexcel International GCSE practice
Linear and binary search. 10 questions in the style of the Edexcel International GCSE exam.
Sample questions
How does a linear search find an item in a list?
- It checks the middle item and discards half the list
- It checks each item in turn, starting from the first
- It sorts the list first and then checks the last item
- It checks items at random until it finds the target
Write a program that reads a whole number n, then n names one per line, then a target name. Use a linear search to print the index (counting from 0) of the first name that matches the target, or `Not found` if it is not in the list.
Write a program that reads a whole number n, then n whole numbers in ascending order (one per line), then a target number. Use a binary search to print the index of the target (counting from 0), or -1 if it is not in the list.