5.3 Coding & Computational Thinking in Ontario Math
Key Takeaways
- The 2020 Ontario Curriculum embeds coding in Strand C (Algebra) from Grades 1-9 to develop computational thinking and algorithmic problem solving.
- The four pillars of computational thinking in math are decomposition, pattern recognition, abstraction, and algorithm design.
- Essential coding constructs include sequential logic, conditional statements (IF-THEN-ELSE), and loops (FOR count-controlled, WHILE condition-controlled).
- Execution tracing and debugging rely on trace tables to track variable states systematically and fix logical errors like off-by-one or initialization bugs.
5.3 Coding & Computational Thinking in Ontario Math
With the release of the revised 2020 Ontario Elementary Mathematics Curriculum (Grades 1–8) and the 2021 De-streamed Grade 9 Course (MTH1W), Coding and Computational Thinking were formally integrated into Strand C: Algebra. Knowing what coding looks like in the Ontario program matters for the MPT's pedagogy component: The Program in Mathematics and The Mathematical Processes are named sections of the Mathematics Curriculum Context dimension, and Strand C is where coding lives.
Scope note. Coding and computational thinking are not among EQAO's published fundamental knowledge and skills for the mathematics content component (Number Sense; Relationships and Proportional Reasoning; Measurement). Do not expect to trace pseudo-code for marks in Section 2 or Section 3. Study this section to understand the curriculum you will be asked about, and because tracing an algorithm is excellent practice for the multi-step arithmetic and linear-relations reasoning that the mathematics component genuinely does assess.
1. The Four Pillars of Computational Thinking in Math
Computational thinking is a problem-solving process that formulates mathematical tasks so that their solutions can be executed by a computer or systematic algorithm.
graph LR
A["Math Problem"] --> B["Decomposition"]
B --> C["Pattern Recognition"]
C --> D["Abstraction"]
D --> E["Algorithm Design"]
- Decomposition: Breaking a complex mathematical problem into smaller, manageable sub-problems (e.g., separating total revenue calculation into calculating individual unit sales and applying discounts).
- Pattern Recognition: Identifying trends, rules, or repeating structures in data or numerical sequences (e.g., discovering first differences in linear relations).
- Abstraction: Stripping away non-essential details to focus on general mathematical formulas or algebraic logic (e.g., converting specific numeric steps into a general formula $y = mx + b$).
- Algorithm Design: Developing a step-by-step, ordered set of instructions (pseudo-code) to solve the problem systematically.
2. Core Programming Constructs in Pseudo-code
In Ontario classroom resources, algorithms are usually presented in language-agnostic pseudo-code. Understanding the fundamental control structures is what lets a teacher read, run, and repair student code.
A. Variables & Assignment
- Assignment Operator (
SETor<-): Stores a value in a variable. - Key Distinction: In algebra, $x = x + 1$ is an impossible equation. In programming,
SET x = x + 1takes the current stored value of $x$, adds 1, and overwrites $x$ with the new result.
SET total = 0
SET rate = 15.50
SET hours = 40
SET total = rate * hours
B. Sequential Logic
Instructions execute in exact sequential order from top to bottom, one line at a time.
C. Conditional Control Structures (IF-THEN-ELSE)
Conditionals allow an algorithm to branch and execute different mathematical calculations based on whether a Boolean condition evaluates to TRUE or FALSE.
IF hours > 40 THEN
SET overtimeHours = hours - 40
SET pay = (40 * rate) + (overtimeHours * rate * 1.5)
ELSE
SET pay = hours * rate
END IF
D. Looping Control Structures (Repetition)
Loops allow code blocks to execute repeatedly without duplicating lines.
- Count-Controlled Loop (
FORLoop): Executes a predetermined number of times.
SET sum = 0
FOR i FROM 1 TO 5 DO
SET sum = sum + i
END FOR
- Condition-Controlled Loop (
WHILEorREPEAT-UNTILLoop): Executes continuously as long as a Boolean condition remains true (or until a condition becomes true).
SET balance = 1000
SET month = 0
WHILE balance < 2000 DO
SET balance = balance * 1.05
SET month = month + 1
END WHILE
3. Systematic Execution Tracing & Trace Tables
To trace pseudo-code accurately during an examination, construct a Trace Table. A trace table tracks line execution step-by-step alongside variable values and condition checks.
Example Trace Walkthrough
Consider the following algorithm designed to accumulate the sum of odd numbers:
Line 1: SET sum = 0
Line 2: FOR k FROM 1 TO 4 DO
Line 3: SET oddNum = (2 * k) - 1
Line 4: SET sum = sum + oddNum
Line 5: END FOR
Line 6: PRINT sum
Executed Trace Table:
| Line # | Iteration ($k$) | oddNum Calculation | sum Value | Condition / Notes |
|---|---|---|---|---|
| Line 1 | — | — | 0 | Initialize sum |
| Line 2 | $k = 1$ | — | 0 | Start Loop ($k=1$) |
| Line 3 | $k = 1$ | $(2 \times 1) - 1 = 1$ | 0 | Compute odd number |
| Line 4 | $k = 1$ | 1 | $0 + 1 = 1$ | Update sum |
| Line 2 | $k = 2$ | — | 1 | Next Loop ($k=2$) |
| Line 3 | $k = 2$ | $(2 \times 2) - 1 = 3$ | 1 | Compute odd number |
| Line 4 | $k = 2$ | 3 | $1 + 3 = 4$ | Update sum |
| Line 2 | $k = 3$ | — | 4 | Next Loop ($k=3$) |
| Line 3 | $k = 3$ | $(2 \times 3) - 1 = 5$ | 4 | Compute odd number |
| Line 4 | $k = 3$ | 5 | $4 + 5 = 9$ | Update sum |
| Line 2 | $k = 4$ | — | 9 | Final Loop ($k=4$) |
| Line 3 | $k = 4$ | $(2 \times 4) - 1 = 7$ | 9 | Compute odd number |
| Line 4 | $k = 4$ | 7 | $9 + 7 = 16$ | Update sum |
| Line 6 | — | — | 16 | Output Printed: 16 |
4. Debugging Common Mathematical Algorithm Errors
Debugging—identifying and correcting errors in mathematical algorithms—is an expectation of Strand C in the Ontario curriculum, and knowing the common failure modes helps you reason about the curriculum in pedagogy scenarios.
Common Algorithm Errors
- Off-by-One Errors: Loop bounds execute one too many or one too few times (e.g.,
FOR i FROM 1 TO N-1instead of1 TO N). - Incorrect Initializer Values: Setting accumulators to the wrong starting value.
- For addition/summation: Initialize to
0(SET sum = 0). - For multiplication/factorials: Initialize to
1(SET product = 1). Initializing to 0 causes all future products to equal 0.
- For addition/summation: Initialize to
- Infinite Loops: Forgetting to update the control variable inside a
WHILEloop (e.g., failing to incrementcounter = counter + 1). - Inverted Logic Operators: Using
<instead of>or failing to include equality (>=).
5. Step-by-Step Worked Examples
Worked Example 1: Execution Trace of a Conditional Loop
Problem: Determine the final printed output of the following pseudo-code algorithm:
SET count = 0
SET total = 50
WHILE total > 15 DO
IF total MOD 2 == 0 THEN
SET total = total - 10
ELSE
SET total = total - 5
END IF
SET count = count + 1
END WHILE
PRINT count
(Note: MOD computes the remainder after integer division).
Solution:
-
Iteration 1:
total = 50. Conditiontotal > 15isTRUE.50 MOD 2 == 0isTRUE(even).totalbecomes $50 - 10 = 40$.countbecomes $0 + 1 = 1$. -
Iteration 2:
total = 40. Conditiontotal > 15isTRUE.40 MOD 2 == 0isTRUE(even).totalbecomes $40 - 10 = 30$.countbecomes $1 + 1 = 2$. -
Iteration 3:
total = 30. Conditiontotal > 15isTRUE.30 MOD 2 == 0isTRUE(even).totalbecomes $30 - 10 = 20$.countbecomes $2 + 1 = 3$. -
Iteration 4:
total = 20. Conditiontotal > 15isTRUE.20 MOD 2 == 0isTRUE(even).totalbecomes $20 - 10 = 10$.countbecomes $3 + 1 = 4$. -
Loop Termination Check:
total = 10. Condition10 > 15isFALSE. The loop terminates. Final Printed Value:count = 4.
6. Pedagogical Note for Ontario Classrooms
In Ontario schools, teachers connect block-based platforms (such as Scratch or Lynx) to math concepts. For instance, creating scripts to draw regular polygons requires computing interior/exterior angles ($360^{\circ} / n$), directly combining geometry with loop controls.
Consider the following pseudo-code algorithm: SET sum = 0 FOR i FROM 1 TO 4 DO SET sum = sum + (2 * i) END FOR PRINT sum What value is printed when this program finishes executing?
A teacher writes a pseudo-code program to check if a student passes a math module requiring a score of at least 70%. Which conditional structure correctly implements this rule?
Consider the following algorithm designed to calculate the factorial of a positive integer N: SET result = 0 FOR k FROM 1 TO N DO SET result = result * k END FOR PRINT result When tested with N = 4, the program outputs 0 instead of the expected factorial value of 24. What is the bug in this algorithm?