Reading and tracing complex pseudocode

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Reading and tracing complex pseudocode

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does tracing follow an algorithm's lines in execution order?
A Yes
B No
2. Does the inner loop reset each time the outer loop advances?
A No
B Yes
3. In this example, does j change faster than i?
A No
B Yes
4. Does DISPLAY i run only when the IF condition is true?
A Yes
B No
5. Can tracing help predict an algorithm's final output?
A Yes
B No

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Execution order AThe inner loop that resets each outer pass
2FOR j FROM 1 TO 2 BThe exact sequence in which an algorithm's lines run
3Runs only when j equals 2 CWrong - the inner loop restarts every outer pass
4Following code by hand to predict its output DWrong - tracing must follow every line in order
5The inner loop never resets between outer passes ETracing
6Tracing can skip lines to save time FDISPLAY i

Definitions

Execution order

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
The outer loop runs from 1 to _
2.
The inner loop runs from 1 to _
3.
DISPLAY i runs when j _ 2
4.
Trace tables help ______ execution
5.
Nested loops run the _____ code repeatedly

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A The outer loop runs 3 times
B The inner loop runs 2 times
C DISPLAY i never runs at all
Question 2
A FOR i FROM 1 TO 3
B FOR j FROM 1 TO 2
C IF j = 2 THEN
D This runs before the outer loop
Question 3
A i counts the outer passes
B j never resets each outer pass
C j counts the inner passes
Question 4
A DISPLAY i shows j's value
B IF j = 2 THEN checks a value
C DISPLAY i shows i's value
D j resets each outer pass
Question 5
A The algorithm has two loops
B One loop is nested inside another
C j resets on each outer pass
D DISPLAY runs when j equals 2
E Tracing ignores loop order

Answer Key

Reading and tracing complex pseudocode
Section A: Quick Questions
Q1
A — Yes
Q2
B — Yes
Q3
B — Yes
Q4
A — Yes
Q5
A — Yes
Section B: Match the Pairs
Q1
Execution order → The exact sequence in which an algorithm's lines run
Q2
FOR j FROM 1 TO 2 → The inner loop that resets each outer pass
Q3
Runs only when j equals 2 → DISPLAY i
Q4
Following code by hand to predict its output → Tracing
Q5
The inner loop never resets between outer passes → Wrong - the inner loop restarts every outer pass
Q6
Tracing can skip lines to save time → Wrong - tracing must follow every line in order
Section C: Definitions
Q1
Execution order — The exact sequence in which an algorithm's lines run, followed step by step to trace its behaviour.
Section D: Fill in the Blanks
Q1
The outer loop runs from 1 to 3
Q2
The inner loop runs from 1 to 2
Q3
DISPLAY i runs when j = 2
Q4
Trace tables help follow execution
Q5
Nested loops run the inner code repeatedly
Section E: Spot the Error
Q1
C — DISPLAY i does run - whenever j equals 2.
Q2
D — The inner code runs inside the outer loop, not before it.
Q3
B — j does reset to 1 at the start of each outer pass.
Q4
A — DISPLAY i shows the value of i, not j.
Q5
E — Tracing must follow the exact order the loops execute in.