Cambridge O Level Computer Science 2210 · 7.7 Trace tables

Q63 · 2210/22/M/J/25 Q6

Worked solution from the Algorithm design and problem-solving Paper 2 Algorithms, Programming and Logic booklet, Part 6 of 8.

Q632210/22/M/J/25original Q6Structured · 10 marks
Question 6 from 2210/22/M/J/25

Worked solution

(a)

Run the algorithm line by line. V1 and V2 move towards each other. RACECAR reads the same both ways, so the loop ends when V1 and V2 meet. TREAT fails at the second check (R and A).

NumberIndexWordContinueV1V2L1L2OUTPUT
2
1RACECARTRUE17RR
26AA
35CC
44Successful
2TREATTRUE15TT
24RA
FALSENOT successful

Number and Index columns correct [1]

Word column correct [1]

Continue column correct [1]

V1 and V2 columns correct [1]

L1 and L2 columns correct [1]

OUTPUT column correct [1]

(b)

State what the algorithm finds:

It checks whether a word reads the same forwards and backwards (a palindrome) [1]

(c)

Explain the two pointers V1 and V2. Any three of these:

V1 marks the start and V2 marks the end of the part of the word being checked [1]

After each check V1 is increased by 1 and V2 is decreased by 1, moving towards the middle [1]

When V1 = V2 or V1 > V2 (they meet or cross) all the letters have been checked, so the WHILE loop stops [1]

The algorithm also stops early if two compared letters are different (Continue becomes FALSE). This also scores, but the part is marked out of 3.

KEY IDEATwo pointers moving inwards from each end check a word, and the loop stops when they meet or a pair does not match.
TOTAL 10 marks

Official mark scheme

Mark scheme for 2210/22/M/J/25 question 6
VIDEO
▶ Topic lesson

A lesson on this topic · by Mr Bulmer's Learning Zone. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.