Setting up the variable columns of a trace table

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

Setting up the variable columns of a trace table

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. How many columns does a trace table need for the variables Total, Count and Average?
A One column only, shared by all three variables
B One column for each variable: three columns
2. In what order should the variable columns be placed in a trace table?
A The order the variables first appear in the algorithm
B Alphabetical order of the variable names
3. An algorithm has DECLARE Num : INTEGER and DECLARE Total : INTEGER. What goes in the column headings?
A Num and Total
B INTEGER and INTEGER
4. A FOR loop uses the counter variable i. Should the trace table include a column for i?
A Yes, the loop counter is a variable and needs its own column
B No, loop counters are handled by the loop so they are left out
5. A new row is made and Total does not change in that step. What should you put in the Total cell?
A Write 0 in the cell
B Leave the cell blank

Match the Pairs

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

Left columnRight column
1DECLARE Total : INTEGER ADECLARE Num : INTEGER DECLARE Sum : INTEGER DECLARE Count : INTEGER
2FOR Count ← 1 TO 4 BTotal needs its own column in the trace table, placed in the order the variable first appears
3Variables are listed as columns in the order they first appear in the algorithm CSum ← 0
4A starting value is entered in the first row of the variable's column DCount and Num have no columns. Each variable must have its own column.
5A trace table with only one column, Total, for an algorithm that declares Total, Count and Num EThe loop counter Count also gets its own column, and its value changes on each pass of the loop
6Row 1: Count = 1, Total = 5 Row 2: Count = 1, Total = 5 (Count repeated) FCount is written again even though it did not change. The cell should be left blank.

Definitions

one column per variable

Fill in the Blanks

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

1.
DECLARE Total : INTEGER DECLARE Count : INTEGER Columns: Total | _____ | OUTPUT
2.
FOR Num ← 1 TO 3 Total ← Total + Num Columns: ___ | Total | OUTPUT
3.
_______ Score : INTEGER // Score gets its own trace table column
4.
DECLARE Total : INTEGER _____ ← 0 // The Total column starts at 0
5.
Count ← Count + 1 // Total unchanged: leave its cell _____

Spot the Error

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

Question 1
A DECLARE Total : INTEGER
B DECLARE Count : INTEGER
C Total = 0
D Count ← 0
Question 2
A DECLARE Num : INTEGER
B DECLARE Total : INTEGER
C Total ← 0
D FOR Count = 1 TO 3
E INPUT Num
F NEXT Count
Question 3
A // Total ← 0 then Num ← 4
B Num | Total | OUTPUT
C 0 | |
D | 4 |
Question 4
A DECLARE Score : INTEGER
B DECLARE Name STRING
C INPUT Name
D INPUT Score
Question 5
A // Count ← 1, OUTPUT Count
B Count | OUTPUT
C 1 |
D 1 | 1

Answer Key

Setting up the variable columns of a trace table
Section A: Quick Questions
Q1
B — One column for each variable: three columns
Q2
A — The order the variables first appear in the algorithm
Q3
A — Num and Total
Q4
A — Yes, the loop counter is a variable and needs its own column
Q5
B — Leave the cell blank
Section B: Match the Pairs
Q1
DECLARE Total : INTEGER → Total needs its own column in the trace table, placed in the order the variable first appears
Q2
FOR Count ← 1 TO 4 → The loop counter Count also gets its own column, and its value changes on each pass of the loop
Q3
Variables are listed as columns in the order they first appear in the algorithm → DECLARE Num : INTEGER DECLARE Sum : INTEGER DECLARE Count : INTEGER
Q4
A starting value is entered in the first row of the variable's column → Sum ← 0
Q5
A trace table with only one column, Total, for an algorithm that declares Total, Count and Num → Count and Num have no columns. Each variable must have its own column.
Q6
Row 1: Count = 1, Total = 5 Row 2: Count = 1, Total = 5 (Count repeated) → Count is written again even though it did not change. The cell should be left blank.
Section C: Definitions
Q1
one column per variable — To set up a trace table, give each variable its own column in the order they first appear, then add a row each time a value changes. Leave unchanged cells blank.
Section D: Fill in the Blanks
Q1
DECLARE Total : INTEGER DECLARE Count : INTEGER Columns: Total | Count | OUTPUT
Q2
FOR Num ← 1 TO 3 Total ← Total + Num Columns: Num | Total | OUTPUT
Q3
DECLARE Score : INTEGER // Score gets its own trace table column
Q4
DECLARE Total : INTEGER Total ← 0 // The Total column starts at 0
Q5
Count ← Count + 1 // Total unchanged: leave its cell blank
Section E: Spot the Error
Q1
C — Assignment uses ←, not =. In Cambridge pseudocode = is a comparison. Total ← 0 sets the starting value, which goes in the first row of the Total column.
Q2
D — A FOR loop sets its counter with ←, so it should be FOR Count ← 1 TO 3. The loop counter Count gets its own column in the trace table, and its starting value 1 goes in the first row.
Q3
B — Columns go in the order the variables first appear in the algorithm. Total is set before Num, so the header should be Total | Num | OUTPUT.
Q4
B — A DECLARE needs a colon between the identifier and its data type: DECLARE Name : STRING. Every DECLAREd variable then gets its own trace table column.
Q5
D — Count does not change when it is output, so its cell should be left blank: ' | 1'. Only write a value in a cell when that variable changes.