Skip to main content
A-LevelComputer ScienceAlgorithm design and problem-solving9618/21 · May/June 2025 · Q411 Marks

Study the algorithm: DECLARE Chars : ARRAY[1:4] OF CHAR DECLARE I, J : INTEGER DECLARE Key : CHAR I ← 2 Chars[1] ← 'D' Chars[2] ← 'T' Chars[3] ← 'H' Chars[4] ← 'R' WHILE I <= 4 Key ← Chars[I] J ← I - 1 WHILE J >= 0 AND Chars[J] > Key Chars[J + 1] ← Chars[J] J ← J - 1 ENDWHILE Chars[J + 1] ← Key I ← I + 1 ENDWHILE

  1. (a)The outer loop structure used in the algorithm is not the most appropriate one to use. State the type of loop structure that would be the most appropriate to use and justify why it is the most appropriate. Loop structure Justification[2]
  2. (b)Complete the trace table by dry running the algorithm. The first row has been completed. | I | Key | J | Chars[J] | Chars[1] | Chars[2] | Chars[3] | Chars[4] | |---|-----|---|----------|----------|----------|----------|----------| | 2 | | | | 'D' | 'T' | 'H' | 'R' |[9]

Mark scheme

Marking points from the official mark scheme (May/June 2025). The mark or mark type is shown in brackets.

  1. [1] Count-controlled
  2. [1] The number of iterations required is known
  3. [1] For I=3, Key becomes 'H', J becomes 2, Chars[J] (Chars[2]) is 'T'
  4. [1] Chars[2] is updated to 'H'
  5. [1] For I=3, J becomes 1, Chars[J] (Chars[1]) is 'D'
  6. [1] For I=4, Key becomes 'R', J becomes 3, Chars[J] (Chars[3]) is 'T'
  7. [1] For I=4, J becomes 2, Chars[J] (Chars[2]) is 'H'
  8. [1] Final Chars array values: ['D', 'H', 'R', 'T']

Write your answer and get it marked

On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.

Sign up free →

About this question

Topic
Algorithm design and problem-solving, A-Level Computer Science (syllabus 9618). Structured question, 11 marks.
Source
A-Level Computer Science, May/June 2025 Paper 2 Variant 1, question 4.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep