Order of Operations as a Tree

Category: Arithmetic   Level: 101

3 + 4 × (6 - 2)2 = 3 + 4 × 16 = 67

Draw the expression as a tree: each operation sits above the two things it works on. Evaluate from the leaves up, and the order of operations takes care of itself.

Step through it

Watch it

Animated walkthrough

Step by step

Step 1: Turn the expression into a tree

Each operation sits above the two numbers it combines. Lower in the tree means sooner, so work from the bottom up.

3 + 4 × (6 - 2)2 = ?

Step 1: Turn the expression into a tree

Step 2: Parentheses first

The subtraction sits at the bottom, inside the parentheses. Six minus 2 is 4, and that 4 travels up the tree.

6 - 2 = 4

Step 2: Parentheses first

Step 3: Exponent next

The power node squares the 4 it received. Four squared is 16, not 8: an exponent is repeated multiplication.

42 = 4 × 4 = 16

Step 3: Exponent next

Step 4: Then multiply

The times node gets 4 from the left and 16 from the right. Four times 16 is 64.

4 × 16 = 64

Step 4: Then multiply

Step 5: Add last, at the top

The root waits for everything below it. Three plus 64 is 67. Adding first gives 7 × 16 = 112, a wrong answer said with great confidence.

3 + 64 = 67

Step 5: Add last, at the top

All steps at once

Storyboard

Generate it yourself

cd svg-generator
python3 -m svgmath render order-of-operations-tree --out /tmp/order-of-operations-tree

Source: svgmath/diagrams/order_of_operations.py