Searching Algorithms (AQA GCSE Computer Science): Exam Questions

Exam code: 8525

45 mins11 questions
1
1 mark

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

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

2
1 mark

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

3a
2 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.

3b
2 marks

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

1a
3 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

1b
3 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

2
4 marks

A sample of data is shown in Fig. 4.

0

1

2

3

4

5

6

7

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.

3
2 marks

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

4a
3 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.

4b
4 marks

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

1
4 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.

2a
3 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.

2b
2 marks

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

3
5 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.

4
6 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.