Complete the trace table for the algorithm shown in Figure 1 when the variable stream is given the following value from the user:
"HLLHLH"
You may not need to use every row in the table.
Figure 1
stream ← USERINPUT
buffer ← ""
FOR k ← 0 TO LEN(stream) - 1
IF stream[k] = 'H' THEN
buffer ← buffer + "1"
ELSE
buffer ← buffer + "0"
ENDIF
IF k MOD 3 = 2 THEN
buffer ← ""
ENDIF
ENDFOR
stream | k | buffer |
|---|---|---|
"HLLHLH" |
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.