Skip to content

Course home

Representing algorithms

Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
Question 88

A telemetry unit on an atmospheric weather balloon compresses sensor data using Run-Length Encoding (RLE). To reconstruct the original stream of sensor codes, a scientist writes a decoding algorithm. The algorithm takes two parallel arrays of size N N\,N as input: counts (storing the consecutive occurrence counts of each code) and symbols (storing the corresponding sensor codes).

The pseudocode for this decompression algorithm is shown below.

decoded_string ← ""
outer_index ← 0
WHILE outer_index < N
    inner_index ← 0
    WHILE inner_index < counts[outer_index]
        decoded_string ← decoded_string + symbols[outer_index]
        L1
    ENDWHILE
    L2
ENDWHILE
OUTPUT decoded_string

Choose the statement that must be written at line L1 to ensure that each character run is expanded to its correct length and that the algorithm executes without an infinite loop.

A

outer_index←outer_index+1\text{outer\_index} \leftarrow \text{outer\_index} + 1outer_index←outer_index+1

B

inner_index←inner_index+1\text{inner\_index} \leftarrow \text{inner\_index} + 1inner_index←inner_index+1

C

inner_index←counts[outer_index]\text{inner\_index} \leftarrow \text{counts}[\text{outer\_index}]inner_index←counts[outer_index]

D

inner_index←inner_index+counts[outer_index]\text{inner\_index} \leftarrow \text{inner\_index} + \text{counts}[\text{outer\_index}]inner_index←inner_index+counts[outer_index]

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