Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
Question 37

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].

A

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

B

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

C

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

D

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

Markscheme

Representing algorithms Questions

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

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.

Question bank