Trace Table Interactive Quiz

Test your algorithmic tracking and dry-run execution accuracy across both Cambridge Pseudocode and Python formats.

Quiz Results Completed!

0/10

Instructions

Analyze each question block by executing a quick mental trace table setup on scratch paper. Use the built-in toggle buttons to switch the language display to your preferred exam setup format (Cambridge Pseudocode or Standard Python 3).

Question 1: Iteration Multipliers
What are the final values of X and Y after tracing the loop execution to its end?
DECLARE X, Y : INTEGER
X <-- 2
Y <-- 1
WHILE X < 10 DO
    X <-- X * 2
    Y <-- Y + X
ENDWHILE
x = 2
y = 1
while x < 10:
    x = x * 2
    y = y + x
Question 2: Total Sum Conditions
Determine the exact sequence value recorded down for Total throughout variable trace updates.
DECLARE Total, i : INTEGER
Total <-- 0
FOR i <-- 1 TO 4
    IF i MOD 2 <> 0 THEN
        Total <-- Total + i
    ENDIF
NEXT i
total = 0
for i in range(1, 5):
    if i % 2 != 0:
        total = total + i
Question 3: Post-Condition Target Tracks
How many times does the loop execute when processed through dry-running state values?
DECLARE Count : INTEGER
Count <-- 5
REPEAT
    Count <-- Count - 1
UNTIL Count <= 2
count = 5
while True:
    count = count - 1
    if count <= 2:
        break
Question 4: Boolean Variable Flipping
What is the final state of Flag and K upon execution exit?
DECLARE K : INTEGER
DECLARE Flag : BOOLEAN
K <-- 10
Flag <-- FALSE
WHILE (K > 5) AND (Flag = FALSE) DO
    K <-- K - 2
    IF K = 6 THEN
        Flag <-- TRUE
    ENDIF
ENDWHILE
k = 10
flag = False
while k > 5 and not flag:
    k = k - 2
    if k == 6:
        flag = True
Question 5: Array Linear Matrix Processing
What does a standard variable trace table show for the final entry of Result?
DECLARE Arr : ARRAY[1:4] OF INTEGER
DECLARE Result, p : INTEGER
Arr <-- [3, 5, 2, 8]
Result <-- Arr[1]
FOR p <-- 2 TO 4
    IF Arr[p] > Result THEN
        Result <-- Arr[p]
    ENDIF
NEXT p
arr = [3, 5, 2, 8]
result = arr[0]
for p in range(1, 4):
    if arr[p] > result:
        result = arr[p]
Question 6: Nested Tracking Dimensions
What is the calculated value inside Value upon execution termination?
DECLARE OutLoop, InLoop, Value : INTEGER
Value <-- 0
FOR OutLoop <-- 1 TO 2
    FOR InLoop <-- 1 TO 3
        Value <-- Value + 1
    NEXT InLoop
NEXT OutLoop
value = 0
for out_loop in range(1, 3):
    for in_loop in range(1, 4):
        value = value + 1
Question 7: Substring Extraction Tracks
What target string gets saved inside variable Hold?
DECLARE Word, Hold : STRING
DECLARE ptr : INTEGER
Word <-- "TRACE"
Hold <-- ""
FOR ptr <-- LENGTH(Word) DOWNTO 4
    Hold <-- Hold & MID(Word, ptr, 1)
NEXT ptr
word = "TRACE"
hold = ""
for ptr in range(len(word)-1, 2, -1):
    hold = hold + word[ptr]
Question 8: Integer Division Mechanics
Identify the exact final outputs for DivVal and ModVal.
DECLARE DivVal, ModVal, InputNum : INTEGER
InputNum <-- 17
DivVal <-- InputNum DIV 5
ModVal <-- InputNum MOD 5
input_num = 17
div_val = input_num // 5
mod_val = input_num % 5
Question 9: Alternating Flag Steps
What variable pattern is logged for Toggle during execution phases?
DECLARE Toggle : BOOLEAN
DECLARE c : INTEGER
Toggle <-- TRUE
FOR c <-- 1 TO 3
    Toggle <-- NOT Toggle
NEXT c
toggle = True
for c in range(1, 4):
    toggle = not toggle
Question 10: Fibonacci Sequences
Trace the exact value of NextTerm on the third iteration step.
DECLARE T1, T2, NextTerm, step : INTEGER
T1 <-- 0
T2 <-- 1
FOR step <-- 1 TO 3
    NextTerm <-- T1 + T2
    T1 <-- T2
    T2 <-- NextTerm
NEXT step
t1 = 0
t2 = 1
for step in range(1, 4):
    next_term = t1 + t2
    t1 = t2
    t2 = next_term