Chhetri AcademyGCSE & A level Paper Builder

1.2.4Tracing algorithms and trace tables

Edexcel GCSE Computer Science (1CP2) · Computational thinking › Algorithms

Practise Tracing algorithms and trace tables. 12 exam-style questions plus unlimited generated ones on this subtopic, at up to four difficulty levels, with full mark schemes and a progress tracker. Free, no account needed.

Build a paper on this topic

▶ Watch videos on Tracing algorithms and trace tables (Craig 'n' Dave Edexcel on YouTube) · Practise all of Algorithms

Sample questions

Written for this site in the style of Edexcel exam questions. They are not taken from real past papers.

Question 1Easy6 marks
Look at this program.
01 a = 8
02 b = 3
03 temp = a
04 a = b
05 b = temp
06 print(a, b)
(a) Complete the trace table in {table} to show the values of the variables after each line has run.[4]
[object Object]
(b) State the output of the program.[1]
(c) State the purpose of the variable temp.[1]
Show the answer and mark scheme
(a) Answer: 02: a = 8, b = 3; 03: temp = 8; 04: a = 3; 05: b = 8 (so a = 3, b = 8, temp = 8 at the end)
  • line 02: b = 3 (a is still 8)
  • line 03: temp = 8
  • line 04: a = 3
  • line 05: b = 8
(b) Answer: 3 8
  • 3 8
(c) Answer: It keeps a copy of the original value of a. Without it, this value would be lost when line 04 runs, so the values could not be swapped.
  • to keep a copy of the original value of a (which is overwritten in line 04) so the values can be swapped
Question 2Medium6 marks
A program processes the times, in seconds, taken by five runners in a race.
01 times = [58, 63, 49, 71, 55]
02 fast = 0
03 total = 0
04 for time in times:
05     total = total + time
06     if time < 60:
07         fast = fast + 1
08 average = total / len(times)
09 print(fast, average)
(a) Complete the trace table in {table}. Each row shows the values at the end of one pass through the loop.[3]
[object Object]
(b) State the output of the program.[2]
(c) State the data type of the variable average.[1]
Show the answer and mark scheme
(a) Answer:
time | total | fast
-----+-------+-----
     | 0     | 0
58   | 58    | 1
63   | 121   | 1
49   | 170   | 2
71   | 241   | 2
55   | 296   | 3
  • time column: 58, 63, 49, 71, 55
  • total column: 58, 121, 170, 241, 296
  • fast column: 1, 1, 2, 2, 3
(b) Answer: 3 59.2
  • 3
  • 59.2
(c) Answer: Real (float)
  • real / float
Question 3Hard6 marks
Look at this program.
01 for row in range(1, 5):
02     line = ""
03     for col in range(row, 5):
04         line = line + str(col)
05     print(line)
(a) State the output of the program.[3]
(b) State the total number of times line 04 is executed.[1]
(c) Line 03 is changed to for col in range(1, row + 1):. State the new output.[2]
Show the answer and mark scheme
(a) Answer:
1234
234
34
4
  • 1234 as the first line
  • 234 then 34
  • 4 as the last line, with no other lines
(b) Answer: 10 (4 + 3 + 2 + 1)
  • 10
(c) Answer:
1
12
123
1234
  • 1 then 12
  • 123 then 1234

Related subtopics

Stuck? Get 1-to-1 help. Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.

Book a free trial