Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
Question 44
Easy

A developer is writing an algorithm to compress an input string of black and white pixel colours using Run-Length Encoding (RLE).

Below is the pseudocode designed to compress the entered string, pixel_data.

pixel_data ← USERINPUT
idx ← 0
run_length ← 1
WHILE idx < LEN(pixel_data) - 1
    IF pixel_data[idx] == pixel_data[idx + 1] THEN
        run_length ← run_length + 1
    ELSE
        OUTPUT run_length
        OUTPUT pixel_data[idx]
        [LINE_X]
    ENDIF
    idx ← idx + 1
ENDWHILE
OUTPUT run_length
OUTPUT pixel_data[idx]

Select one option to show what code should be written at point [LINE_X].

run_length←0\text{run\_length} \leftarrow 0run_length←0

run_length←1\text{run\_length} \leftarrow 1run_length←1

OUTPUT run_length\text{OUTPUT run\_length}OUTPUT run_length

idx←idx+1\text{idx} \leftarrow \text{idx} + 1idx←idx+1

Representing algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Representing algorithms