Searching Algorithms (AQA GCSE Computer Science)

Exam Questions

45 mins11 questions
11 mark

State why a binary search cannot be used on the list fruits

fruits = ["banana", "apple", "orange", "pear", "grape", "pineapple"]

Did this page help you?

21 mark

State why binary search is considered a better algorithm than linear search.

Did this page help you?

3a2 marks

A list of valid discount codes is shown below.

[NIC12B, LOR11S, STU12M, VIC08E, KEI99M, WES56O, DAN34S]

State one reason why a binary search would not be able to be used with this data.

3b2 marks

Give the name of one searching algorithm that would be able to be used with this data.

Did this page help you?

1a3 marks

State the comparisons that would be made when the linear search algorithm is used to search for the value 8 in the following array (array indices have been included above the array).

0

1

2

3

4

6

6

4

7

8

13

14

15

17

1b3 marks

State the comparisons that would be made when the binary search algorithm is used to search for the value 8 in the following array (array indices have been included above the array).

0

1

2

3

4

5

6

4

7

8

13

14

15

17

Did this page help you?

24 marks

A sample of data is shown in Fig. 4.

amber

house

kick

moose

orange

range

wind

zebra

Fig. 4

Show the stages of a binary search to find the word zebra using the data shown in Fig. 4.

Did this page help you?

32 marks

State two advantages of a linear search compared to a binary search.

Did this page help you?

4a3 marks

You are given two different lists of data: one sorted and one unsorted.

List A (Unsorted):
["pear", "orange", "banana", "apple", "mango", "grape"]

List B (Sorted):
["apple", "banana", "grape", "lemon", "mango", "orange", "pear", "watermelon"]

Explain, step by step, how you would use a linear search to find the word 'mango' in List A.

4b4 marks

Explain, step by step, how you would use a binary search to find the word 'mango' in List B.

Did this page help you?

14 marks

Compare the advantages and disadvantages of both linear and binary search algorithms.

Explain in which scenarios one algorithm would be preferred over the other.

Did this page help you?

2a3 marks

A section of code from a linear search is given below

list = [7, 1, 4, 2, 8]
target = 4
found = False

# Loop through each element in the list
for _____ in _____(0,___(list) - 1):

Complete the missing Python code to correctly loop through each element in the list.

2b2 marks

State the purpose of -1 in the loop in part A.

Did this page help you?

35 marks

You are given the following sorted list of numbers:

[2, 9, 15, 22, 30, 41, 53, 66, 71, 83, 97]

Complete a binary search to find the number 22.

Show each step in the search, indicating the middle element and how the list is divided at each step.

Did this page help you?

46 marks

You are given the following sorted list of words:

["apple", "banana", "cherry", "grape", "lemon", "mango", "orange", "peach", "pear", "plum", "watermelon"]

Complete a binary search to find the word peach.

Show each step in the search, indicating the middle element and how the list is divided at each step.

Did this page help you?