Testing Algorithms with Trace Tables (Desk Checks and Dry Runs)

How do you know your algorithm works before you type it into a computer? You do a desk check (also called a dry run): you pretend to be the computer and follow each step with pencil and paper, using a trace table to record the values.

Build on what you learned in Forms 1–3

These Lower School ICT posts cover the basics of this topic:

In this post:

  • What is a desk check / dry run?
  • How to build a trace table
  • Worked example with a loop
  • Using a trace table to find an error
  • Choosing test data

Desk checks and trace tables

A trace table has a column for each variable (identifier) and, if needed, a column for the output. You fill in one row for each pass (each time the loop runs or a value changes). At the end, compare the output with what you expected – if they match, the algorithm is correct for that test data.

Steps to complete a trace table

  1. Draw a column for each variable, plus Output.
  2. Go through the algorithm one line at a time.
  3. Every time a variable is given a new value, write it in its column (on a new row for each pass of a loop).
  4. When something is printed, write it in the Output column.
  5. Keep going until the algorithm ends.

Worked example

Pseudocode

1  total ← 0
2  count ← 1
3  WHILE count <= 4 DO
4      total ← total + count * 2
5      count ← count + 1
6  ENDWHILE
7  PRINT total
PasscounttotalOutput
Start10
122
236
3412
4520
End (count <= 4 is FALSE)52020

Notice that total goes 0 → 2 → 6 → 12 → 20, because each time we add count × 2 (2, 4, 6, 8). When count becomes 5, the condition count <= 4 is FALSE, so the loop stops and 20 is printed.

Using a trace table to find an error

Kerry-Ann wants to find the average of 3 numbers but her algorithm says average ← num1 + num2 + num3 / 3. Trace it with 60, 70 and 80:

num1num2num3averageExpected
607080156.6770

The trace table shows the answer is wrong. Only num3 was divided by 3! The fix is average ← (num1 + num2 + num3) / 3. This is a logic error – more on that in Section 8.

Choosing test data

Test with normal data (typical values), boundary data (values right at the edge, e.g. a mark of exactly 50 when the pass mark is 50) and erroneous data (values that should be rejected, like a mark of −5).

Try it: Trace table filler

Complete the trace table for this algorithm. Each row shows the values at the end of that pass.

x ← 3
y ← 1
FOR i ← 1 TO 3 DO
    y ← y * x
    x ← x − 1
ENDFOR
PRINT y
iyx
(start)13
1
2
3

What is printed at the end? (Answer: 6.)

Related

Related class recordings:
• How to Approach a Dry run using test data and trace tables to uncover errors in your algorithm
• Trace Table Exercise – Form 5 Opt D – 2025-10-08_08-55-28
• Reinforcement of Control Structures, Trace table test – Live class 5 OptD (2026-10-07_09-56-46)

Paper 1 practice (multiple choice)

Choose the best answer for each question. Try them all before you check.

1. A trace table is used to
(A) translate a program
(B) test an algorithm by recording the values of variables
(C) draw a flowchart
(D) store a program

2. In a trace table, the column headings are usually
(A) the line numbers only
(B) the variable names (identifiers)
(C) the flowchart symbols
(D) the programmer’s name

3. Working through an algorithm by hand to check it is called a
(A) compile
(B) dry run
(C) syntax check
(D) link

4. Given x ← 5, then x ← x + 3, then x ← x * 2, the final value of x is
(A) 10
(B) 16
(C) 13
(D) 8

5. Testing a pass-mark program with a mark of exactly 50 uses
(A) erroneous data
(B) boundary (extreme) data
(C) random data
(D) no data

Show answers

1. B
2. B
3. B
4. B
5. B

Paper 2 practice (structured question)

Study the following algorithm:

sum ← 0
FOR n ← 1 TO 4 DO
    READ value
    sum ← sum + value
ENDFOR
average ← sum / 4
PRINT sum, average

(a) Explain what is meant by a “dry run”. (2 marks)

(b) Copy and complete a trace table for the algorithm using the data 6, 3, 9, 2. (4 marks)

(c) State the output of the algorithm for this data:

(i) the sum (1 mark)

(ii) the average (1 mark)

(d) Identify the type of loop used in the algorithm. (1 mark)

Total: 9 marks

Show answers

(a) Working through the algorithm by hand, step by step (1 mark), recording the values of variables to check that the results are correct (1 mark).

(b)
• n = 1, value = 6, sum = 6 (1 mark)
• n = 2, value = 3, sum = 9 (1 mark)
• n = 3, value = 9, sum = 18 (1 mark)
• n = 4, value = 2, sum = 20 and average = 5 (1 mark)

(c)

(i) 20 (1 mark)

(ii) 5 (1 mark)

(d) FOR loop / counter-controlled loop (1 mark).

Next: Low-Level vs High-Level Languages and the Steps in Implementing a Program

Syllabus link: This post is relevant to the CSEC® Information Technology Syllabus (CXC 30/G/SYLL 17), Section 7: Problem-Solving and Program Design, Specific Objective 7 (“test algorithms for correctness”).

Attributions to media used in this post:

No third-party images are used in this post. Embedded videos are credited on YouTube to their channels.

© 2026 Vedesh Kungebeharry. All rights reserved.

Operators in Algorithms: Arithmetic, Relational and Logical Operators, Truth Tables, MOD and DIV

Algorithms do calculations and make decisions using operators. In this post you will learn the arithmetic operators (including MOD and DIV), the relational operators used to compare values, and the logical operators AND, OR, NOT with their truth tables.

Build on what you learned in Forms 1–3

These Lower School ICT posts cover the basics of this topic:

In this post:

  • Arithmetic operators, MOD and DIV
  • Relational operators
  • Logical operators AND, OR, NOT
  • Truth tables
  • Using operators in pseudocode and code

Arithmetic operators

OperatorMeaningExampleResult
+Add7 + 310
−Subtract7 − 34
*Multiply7 * 321
/Divide7 / 23.5
DIVWhole-number (integer) division – how many times it goes in17 DIV 53
MODRemainder after whole-number division17 MOD 52

MOD and DIV are very useful. Example: a fete has 135 minutes of music. 135 DIV 60 = 2 hours and 135 MOD 60 = 15 minutes. Another common use: a number is even if number MOD 2 = 0.

Pseudocode

READ total_minutes
hours ← total_minutes DIV 60
minutes ← total_minutes MOD 60
PRINT total_minutes, " minutes = ", hours, " hours and ", minutes, " minutes"

Python

# Convert minutes into hours and minutes using DIV and MOD
total_minutes = int(input("Enter the number of minutes: "))
hours = total_minutes // 60      # DIV
minutes = total_minutes % 60     # MOD
print(total_minutes, "minutes =", hours, "hours and", minutes, "minutes")

C

/* Convert minutes into hours and minutes using DIV and MOD */
#include <stdio.h>

int main(void)
{
    int total_minutes, hours, minutes;

    printf("Enter the number of minutes: ");
    scanf("%d", &total_minutes);
    hours = total_minutes / 60;      /* DIV (integer division) */
    minutes = total_minutes % 60;    /* MOD (remainder) */
    printf("%d minutes = %d hours and %d minutes\n", total_minutes, hours, minutes);
    return 0;
}

Sample run with 135: 135 minutes = 2 hours and 15 minutes. In Python, DIV is // and MOD is %; in C, / between two integers does DIV and % is MOD.

Relational operators

Relational operators compare two values. The answer is always TRUE or FALSE.

CSEC pseudocodeMeaningPythonC
<less than<<
>greater than>>
=equal to====
<=less than or equal to<=<=
>=greater than or equal to>=>=
<>not equal to!=!=

Example: IF age >= 17 THEN PRINT "You may apply for a learner’s permit". You can practise these in Relational Operators – A practical Exercise.

Logical operators and truth tables

  • AND – TRUE only if both conditions are TRUE.
  • OR – TRUE if at least one condition is TRUE.
  • NOT – reverses the value: NOT TRUE = FALSE.

A truth table shows the result for every possible combination of inputs.

ABA AND BA OR B
TRUETRUETRUETRUE
TRUEFALSEFALSETRUE
FALSETRUEFALSETRUE
FALSEFALSEFALSEFALSE
ANOT A
TRUEFALSE
FALSETRUE

Everyday example: A child gets into the Carnival kiddies’ fete free IF they are under 12 AND with an adult. A 10-year-old alone → TRUE AND FALSE = FALSE, so no free entry. A scholarship is given IF average >= 80 OR the student won the science fair – only one needs to be TRUE.

Pseudocode

READ age, with_adult
IF age < 12 AND with_adult = TRUE THEN
    PRINT "Free entry"
ELSE
    PRINT "Pay at the gate"
ENDIF

In Python these are written and, or, not; in C they are &&, || and !.

Optional extension: how computers use AND, OR and NOT (Boolean logic) at the hardware level.

Video: Boolean Logic & Logic Gates: Crash Course Computer Science #3 – https://www.youtube.com/watch?v=gI-qXk7XojA

Try it: Complete the truth table

Type TRUE or FALSE in each box, then check.

ABA AND BA OR BNOT A
TRUETRUE
TRUEFALSE
FALSETRUE
FALSEFALSE

Try it: MOD and DIV practice

Work out each answer.

ExpressionAnswer
17 DIV 5
17 MOD 5
20 MOD 4
9 DIV 2
250 MOD 60

Related

Related: Relational Operators – A practical Exercise

Paper 1 practice (multiple choice)

Choose the best answer for each question. Try them all before you check.

1. What is the value of 23 MOD 4?
(A) 5
(B) 3
(C) 5.75
(D) 4

2. What is the value of 23 DIV 4?
(A) 5
(B) 3
(C) 5.75
(D) 6

3. Which relational operator means “not equal to” in CSEC pseudocode?
(A) =
(B) <>
(C) >=
(D) !

4. If A is TRUE and B is FALSE, what is A AND B?
(A) TRUE
(B) FALSE
(C) Both
(D) Cannot tell

5. If A is FALSE and B is TRUE, what is A OR B?
(A) TRUE
(B) FALSE
(C) NOT B
(D) Cannot tell

Show answers

1. B
2. A
3. B
4. B
5. A

Paper 2 practice (structured question)

A minibus company charges students half price IF they are in uniform AND travelling before 6:00 p.m. A program uses the Boolean variables in_uniform and before_six.

(a) State the result of EACH of the following:

(i) 29 MOD 7 (1 mark)

(ii) 29 DIV 7 (1 mark)

(b) Copy and complete a truth table for in_uniform AND before_six, showing all FOUR combinations. (4 marks)

(c) Explain the difference between the AND and OR logical operators. (2 marks)

(d) Write a pseudocode IF statement that prints “Half price” when a student qualifies, and “Full price” otherwise. (2 marks)

Total: 10 marks

Show answers

(a)

(i) 1 (1 mark)

(ii) 4 (1 mark)

(b)
• TRUE, TRUE → TRUE (1 mark)
• TRUE, FALSE → FALSE (1 mark)
• FALSE, TRUE → FALSE (1 mark)
• FALSE, FALSE → FALSE (1 mark)

(c) AND gives TRUE only when both conditions are TRUE (1 mark); OR gives TRUE when at least one of the conditions is TRUE (1 mark).

(d) IF in_uniform = TRUE AND before_six = TRUE THEN PRINT “Half price” (1 mark); ELSE PRINT “Full price” ENDIF (1 mark).

Next: Testing Algorithms with Trace Tables (Desk Checks and Dry Runs)

Syllabus link: This post is relevant to the CSEC® Information Technology Syllabus (CXC 30/G/SYLL 17), Section 7: Problem-Solving and Program Design, Specific Objective 6 (“represent algorithms in the form of flowchart and pseudocode”).

Attributions to media used in this post:

No third-party images are used in this post. Embedded videos are credited on YouTube to their channels.

Updates

2026/10/16

– Syntax highlighting added to code examples.

© 2026 Vedesh Kungebeharry. All rights reserved.

Flowcharts and Pseudocode: Sequence, Selection and Loops

Now that you know what an algorithm is, you need to be able to write one the way CSEC expects – as a flowchart or in pseudocode. This post covers the flowchart symbols, the pseudocode keywords, and the control structures: sequence, selection and loops (repetition).

Build on what you learned in Forms 1–3

These Lower School ICT posts cover the basics of this topic:

In this post:

  • Flowchart symbols
  • Pseudocode keywords
  • Sequence
  • Selection: IF-THEN, IF-THEN-ELSE and nested IF
  • Loops: FOR, WHILE and REPEAT-UNTIL

Video: Computer Science Basics: Sequences, Selections, and Loops – https://www.youtube.com/watch?v=eSYeHlwDCNA

Flowchart symbols

Start / StopTerminator – start or endInput / OutputInput/Output – read or displayProcessProcess – calculation or assignmentDecision?Decision – a yes/no questionFlow line – shows the direction
The flowchart symbols you need for CSEC.
A simple flowchart for fixing a lamp that does not work. The diamonds are decisions (yes/no questions) and the rectangles are actions.
A simple flowchart for fixing a lamp that does not work. The diamonds are decisions (yes/no questions) and the rectangles are actions.

Image source: File:LampFlowchart.svg

Pseudocode keywords

  • Input: READ or INPUT
  • Output: PRINT, WRITE, OUTPUT or DISPLAY
  • Storing a value (assignment): STORE, or an arrow such as total ← 0 (some teachers use =)
  • Decisions: IF … THEN … ELSE … ENDIF
  • Loops: FOR … ENDFOR, WHILE … ENDWHILE, REPEAT … UNTIL

Sequence

In a sequence, the steps are carried out one after another, in order. Example: find the average of three test scores.

Pseudocode

START
    READ score1, score2, score3
    average ← (score1 + score2 + score3) / 3
    PRINT "The average is ", average
STOP
StartInput score1, score2, score3average ← (s1 + s2 + s3) / 3Output averageStop
Flowchart for the average of three scores (sequence).

Selection

Selection lets the algorithm make a decision and choose which steps to carry out.

IF-THEN-ELSE

START
    READ mark
    IF mark >= 50 THEN
        PRINT "Pass"
    ELSE
        PRINT "Fail"
    ENDIF
STOP
StartInput markmark >= 50?YesNoOutput "Pass"Output "Fail"Stop
Flowchart for the Pass/Fail decision. A decision diamond has two exits: Yes and No.

A nested IF is an IF inside another IF. It is used when there are more than two choices, such as grades:

Nested IF

READ mark
IF mark >= 75 THEN
    PRINT "Grade A"
ELSE
    IF mark >= 60 THEN
        PRINT "Grade B"
    ELSE
        PRINT "Grade C"
    ENDIF
ENDIF

Loops (repetition)

A loop repeats a set of steps. CSEC uses three kinds:

  • FOR loop – repeats a known number of times (counter-controlled).
  • WHILE loop – checks a condition first, and repeats while it is true. It may run zero times.
  • REPEAT-UNTIL loop – does the steps first, then checks the condition at the end, so it always runs at least once.

FOR loop: add up 5 prices

total ← 0
FOR count ← 1 TO 5 DO
    READ price
    total ← total + price
ENDFOR
PRINT "Total: ", total
Starttotal ← 0, count ← 1count <= 5?YesInput pricetotal ← total + pricecount ← count + 1NoOutput totalStop
Flowchart for the FOR loop above. The arrow going back up shows the repetition.

WHILE loop: keep going until -1 is entered (a sentinel or rogue value)

READ mark
WHILE mark <> -1 DO
    IF mark >= 50 THEN
        PRINT "Pass"
    ELSE
        PRINT "Fail"
    ENDIF
    READ mark
ENDWHILE

REPEAT-UNTIL loop: ask for the PIN until it is correct

REPEAT
    READ pin
UNTIL pin = 1234
PRINT "Welcome"

Algorithm and program side by side

Here is a loop like the FOR example turned into real programs (the number of items is read first, and VAT is added as a constant). You will learn how to do this translation in Section 8.

Python

# Total a shopping bill and add VAT
VAT_RATE = 0.125          # constant: 12.5% VAT

num_items = int(input("How many items? "))
subtotal = 0.0
for i in range(num_items):
    price = float(input("Enter price: $"))
    subtotal = subtotal + price
vat = subtotal * VAT_RATE
total = subtotal + vat
print("Subtotal: $" + format(subtotal, ".2f"))
print("VAT: $" + format(vat, ".2f"))
print("Total: $" + format(total, ".2f"))

C

/* Total a shopping bill and add VAT */
#include <stdio.h>

#define VAT_RATE 0.125    /* constant: 12.5% VAT */

int main(void)
{
    int num_items, i;
    float price, subtotal = 0.0, vat, total;

    printf("How many items? ");
    scanf("%d", &num_items);
    for (i = 1; i <= num_items; i++)
    {
        printf("Enter price: $");
        scanf("%f", &price);
        subtotal = subtotal + price;
    }
    vat = subtotal * VAT_RATE;
    total = subtotal + vat;
    printf("Subtotal: $%.2f\n", subtotal);
    printf("VAT: $%.2f\n", vat);
    printf("Total: $%.2f\n", total);
    return 0;
}

Sample run: 3 items costing 25, 40.50 and 10 → Subtotal: $75.50, VAT: $9.44, Total: $84.94.

Try it: Flowchart symbol and control structure matcher

Choose the correct answer for each.

Shape used for “Input price”
Shape used for “total ← total + price”
Shape used for “Is mark >= 50?”
Shape used for “Start” and “Stop”
Loop that repeats a known number of times
Loop that always runs at least once
Loop that checks its condition before running

Related

Related:
• Ways of representing algorithms
• Closure on Sequence with flow charts
• Flowchart Practise – Finding the average of 3 numbers.
• Selection Statements: Practise Exercise(s)
• Using multiple selection statements (By Example)

Paper 1 practice (multiple choice)

Choose the best answer for each question. Try them all before you check.

1. Which flowchart symbol is used for a decision?
(A) Rectangle
(B) Parallelogram
(C) Diamond
(D) Oval

2. Which pseudocode keyword is used to accept data from the user?
(A) PRINT
(B) READ
(C) STORE
(D) ENDIF

3. Which loop is BEST when you know exactly how many times to repeat?
(A) WHILE
(B) REPEAT-UNTIL
(C) FOR
(D) IF-THEN

4. A REPEAT-UNTIL loop differs from a WHILE loop because it
(A) never ends
(B) checks the condition at the end, so it runs at least once
(C) cannot contain IF statements
(D) runs exactly 10 times

5. Carrying out instructions one after the other in order is called
(A) selection
(B) iteration
(C) sequence
(D) nesting

Show answers

1. C
2. B
3. C
4. B
5. C

Paper 2 practice (structured question)

A school canteen gives a 10% discount on any lunch order costing more than $50. Otherwise there is no discount.

(a) Name the flowchart symbol used for EACH of the following:

(i) reading the cost of the order (1 mark)

(ii) checking whether the cost is more than $50 (1 mark)

(b) Write pseudocode to read the cost of ONE order and print the amount to pay after any discount. (5 marks)

(c) State the type of loop you would use to process orders until a cost of 0 is entered, and give ONE reason. (2 marks)

(d) Distinguish between sequence and selection. (2 marks)

Total: 11 marks

Show answers

(a)

(i) Parallelogram / input-output symbol (1 mark)

(ii) Diamond / decision symbol (1 mark)

(b) One mark for each marked line:

READ cost                            (1 mark)
IF cost > 50 THEN                    (1 mark)
    amount ← cost − (cost × 0.10)    (1 mark)
ELSE
    amount ← cost
ENDIF                                (1 mark for ELSE … ENDIF)
PRINT amount                         (1 mark)

(c) WHILE (or REPEAT-UNTIL) loop (1 mark); the number of orders is not known in advance, so the loop must stop when the sentinel value 0 is entered (1 mark).

(d) Sequence: instructions are carried out one after another in order (1 mark). Selection: a condition is tested and a choice is made about which instructions to carry out (1 mark).

Next: Operators in Algorithms: Arithmetic, Relational and Logical Operators, Truth Tables, MOD and DIV

Syllabus link: This post is relevant to the CSEC® Information Technology Syllabus (CXC 30/G/SYLL 17), Section 7: Problem-Solving and Program Design, Specific Objective 6 (“represent algorithms in the form of flowchart and pseudocode”).

Attributions to media used in this post:

Updates

2026/10/16

– Syntax highlighting added to code examples.

© 2026 Vedesh Kungebeharry. All rights reserved.

Defining a Problem with an IPO Chart: Input, Processing and Output

Before you write an algorithm, you must be clear about what goes in, what must happen, and what must come out. CSEC calls this defining a problem by decomposing it into its significant components. The tool we use is the IPO chart (also called a defining diagram).

Build on what you learned in Forms 1–3

These Lower School ICT posts cover the basics of this topic:

In this post:

  • Input, processing and output
  • How to build an IPO chart
  • Worked examples
  • Turning an IPO chart into an algorithm

The three components

  • Input – the data that must be given to the solution (what the user types in or what is read). Look for nouns in the problem such as “the price”, “three marks”, “the number of hours”.
  • Processing – the steps or calculations that change the input into the output. Look for verbs such as “calculate”, “add”, “find”, “compare”.
  • Output – the results the solution must produce or display. Look for words like “print”, “display”, “output”.

An IPO chart is simply a table with three columns: Input, Processing and Output.

Worked example 1: area of a garden plot

Problem: Write an algorithm to read the length and width of a rectangular garden plot and print its area.

InputProcessingOutput
length, widthRead length and width
Calculate area = length × width
Display area
area

Worked example 2: electricity bill

Problem: A customer is charged $0.45 for every kilowatt-hour (kWh) used plus a fixed charge of $20. Read the number of kWh used and print the amount due.

InputProcessingOutput
units used (kWh)Read units
Calculate amount = (units × 0.45) + 20
Display amount
amount due

Notice that the rate ($0.45) and the fixed charge ($20) are not inputs – they are given in the question and never change, so they are constants. You will learn more about this in the next post.

Worked example 3: highest of three cricket scores

Problem: Read the scores of three batsmen and print the highest score.

InputProcessingOutput
score1, score2, score3Read the three scores
Compare the scores to find the highest
Display the highest
highest score

From IPO chart to algorithm

Once the IPO chart is done, the algorithm almost writes itself. For the garden plot:

Pseudocode

START
    READ length, width
    area ← length * width
    PRINT "The area is ", area
STOP

Tip for exams: in the Processing column, write the steps in the order they happen and include the formula. Do not put the output values in the Input column!

Try it: Input, Processing or Output?

A program must read a student’s three test marks, calculate the average and display the average and a “Pass” or “Fail” message. Classify each item.

The three test marks
Add the three marks and divide by 3
The average mark
Check whether the average is 50 or more
The message “Pass” or “Fail”

Paper 1 practice (multiple choice)

Choose the best answer for each question. Try them all before you check.

1. In an IPO chart, the “P” stands for
(A) printing
(B) processing
(C) program
(D) pseudocode

2. A program reads the price of an item and the quantity bought, then displays the total cost. The INPUTS are
(A) total cost only
(B) price and quantity
(C) price, quantity and total cost
(D) quantity only

3. Which of the following belongs in the Processing column?
(A) The number of hours worked
(B) Calculate pay = hours × rate
(C) The pay
(D) A printed payslip

4. An IPO chart is used to
(A) translate a program into machine code
(B) define a problem by breaking it into its components
(C) find syntax errors
(D) store data in memory

5. A program calculates the area of a circle using πr². Which is an input?
(A) π
(B) the radius
(C) the area
(D) the formula

Show answers

1. B
2. B
3. B
4. B
5. B

Paper 2 practice (structured question)

A taxi driver in Kingston charges a fixed fee of $300 plus $150 for every kilometre travelled. A program is needed to read the distance travelled and display the fare.

(a) State the meaning of EACH of the following terms in problem-solving:

(i) input (1 mark)

(ii) output (1 mark)

(b) Draw an IPO chart for the taxi fare problem. (4 marks)

(c) Identify ONE constant in this problem. (1 mark)

(d) Write the formula used in the processing step. (1 mark)

Total: 8 marks

Show answers

(a)

(i) The data that must be supplied to the solution for it to be solved (1 mark)

(ii) The result(s) that the solution must produce or display (1 mark)

(b) Input: distance (1 mark). Processing: read distance (1 mark); calculate fare = 300 + 150 × distance (1 mark). Output: fare (1 mark).

(c) The fixed fee of $300 OR the rate of $150 per kilometre (1 mark).

(d) Fare = 300 + (150 × distance) (1 mark).

Next: Variables, Constants and Data Types: Integer, Real, Character, String and Boolean

Syllabus link: This post is relevant to the CSEC® Information Technology Syllabus (CXC 30/G/SYLL 17), Section 7: Problem-Solving and Program Design, Specific Objective 3 (“define a problem by decomposing it into its significant components”).

Attributions to media used in this post:

No third-party images are used in this post. Embedded videos are credited on YouTube to their channels.

© 2026 Vedesh Kungebeharry. All rights reserved.