Run length encoding (RLE) is a lossless compression algorithm that represents consecutive repeating data values as a count and data pair.
For example, the character sequence AAAAABBBCC can be represented as 5 A 3 B 2 C because there are five 'A's, followed by three 'B's, and finally two 'C's.
The algorithm below in Figure 1 is designed to output the RLE pairs for any text sequence entered by a user.
Three parts of the pseudocode labelled L1, L2, and L3 are missing.
Figure 1
sequence ← USERINPUT
index ← 0
current_run ← 1
WHILE index < LEN(sequence) - 1
IF sequence[index] == sequence[index + 1] THEN
current_run ← current_run + 1
ELSE
OUTPUT current_run
OUTPUT sequence[index]
current_run ← L1
ENDIF
L3
ENDWHILE
OUTPUT current_run
OUTPUT sequence[index]
Which code should be written at point L3 of the algorithm to ensure the sequence is processed correctly without causing an infinite loop?
index←index+1\text{index} \leftarrow \text{index} + 1index←index+1
index←1\text{index} \leftarrow 1index←1
current_run←current_run+1\text{current\_run} \leftarrow \text{current\_run} + 1current_run←current_run+1
index←index+current_run\text{index} \leftarrow \text{index} + \text{current\_run}index←index+current_run
208 exam-style questions on AQA GCSE Computer Science Representing algorithms. Each one has a worked solution and a mark scheme showing where the marks go.