EXAM QUESTIONS · A LEVEL 9618

Computational Thinking (A2) Exam-Style Questions with Answers (A Level 9618)

Original exam-style questions on linear and binary search, insertion and bubble sort, Big O notation, abstract data types including binary trees, and recursion for Cambridge AS & A Level Computer Science 9618 (Paper 4). There are 20 marks in total. Try each question on paper first, then press Show answer to see the mark scheme. Answers that can be calculated mark themselves.

Question 1[3 marks]

A binary search is used to find 47 in this sorted list:

3, 8, 15, 22, 29, 36, 41, 47, 53, 60, 72

State the values compared with 47, in order. (When there is an even number of items, use the lower middle position.)

Show answer

36, 53, 41, 47 [3]

36 is the middle item (position 6); 47 > 36 so search the upper half; middle is 53; 47 < 53 so search 41–47; middle is 41; then 47 is found. 1 mark for 36 first, 1 mark for 53 and 41, 1 mark for the complete correct order.

Question 2[2 marks]

State the list 7, 3, 9, 1, 5 after the first two passes of an insertion sort into ascending order.

Show answer

3, 7, 9, 1, 5 [2]

Pass 1 inserts 3 before 7. Pass 2 takes 9, which is already in place.

Question 3[4 marks]

State the Big O time complexity of each algorithm.

  1. Linear search [1]
  2. Binary search [1]
  3. Bubble sort [1]
  4. Accessing an element of an array by its index [1]
Show answer
  1. O(n) [1]
  2. O(log n) [1]
  3. O(n²) [1]
  4. O(1) [1]
Question 4[3 marks]

The values 50, 30, 70, 20, 40, 60, 80 are inserted, in that order, into an empty binary search tree. State the output of an in-order traversal and of a pre-order traversal.

Show answer
  • In-order: 20, 30, 40, 50, 60, 70, 80 [1] – an in-order traversal of a binary search tree gives the values in ascending order. [1]
  • Pre-order: 50, 30, 20, 40, 70, 60, 80 [1]
Question 5[2 marks]

State the value returned by Sum(5).

FUNCTION Sum(N : INTEGER) RETURNS INTEGER
   IF N <= 1
      THEN
         RETURN 1
      ELSE
         RETURN N + Sum(N - 1)
   ENDIF
ENDFUNCTION
Show answer

15 [2] (5 + 4 + 3 + 2 + 1)

Question 6[3 marks]

Identify the base case and the general case in the function in Question 5, and explain why a base case is needed.

Show answer
  • Base case: IF N <= 1 THEN RETURN 1. [1]
  • General case: RETURN N + Sum(N − 1). [1]
  • Without a base case the function would call itself forever, until the stack overflows. [1]
Question 7[3 marks]

Explain how a compiler uses a stack when a recursive function is called.

Show answer
  • Each call pushes a stack frame containing the return address, parameters and local variables onto the stack. [1]
  • When the base case is reached, the calls start to return. [1]
  • Each frame is popped off in turn (last in, first out), so execution returns to the correct place with the correct values. [1]

Frequently asked questions

Why is binary search faster than linear search?

Binary search halves the number of items left to check after every comparison, so its time complexity is O(log n). Linear search may have to check every item, which is O(n). Binary search only works on sorted data.

Are these past paper questions?

No. These are original exam-style questions written by a Computer Science teacher in the Cambridge style.

Revise the topic: 9618 computational thinking notes · 9618 flashcards · All exam-style questions