33Easy
0/1

Select one option to show what code should be written at point P5 of the algorithm in Figure 1 to correctly decompress a run-length encoded string consisting of single-digit counts followed by their corresponding characters (such as "3A2B" representing "AAABB").

Figure 1

compressed ← USERINPUT
decompressed ← ""
i ← 0
WHILE i < LEN(compressed)
    count ← TO_INTEGER(compressed[i])
    char ← compressed[i + 1]
    j ← 0
    WHILE j < count
        decompressed ← decompressed + char
        j ← j + 1
    ENDWHILE
    P5
ENDWHILE
OUTPUT decompressed

i←i+1i \leftarrow i + 1i←i+1

i←i+2i \leftarrow i + 2i←i+2

i←i+counti \leftarrow i + \text{count}i←i+count

i←i+ji \leftarrow i + ji←i+j

Data compression Questions

Practise AQA GCSE Computer Science Data compression with exam-style questions for GCSE Computer Science. 60 questions, matched to the AQA GCSE Computer Science (8525) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.

PreviousNext

Data compression Questions

  1. GCSE
  2. /Computer Science
  3. /Data compression