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.
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 = ?
The subtraction sits at the bottom, inside the parentheses. Six minus 2 is 4, and that 4 travels up the tree.
6 - 2 = 4
The power node squares the 4 it received. Four squared is 16, not 8: an exponent is repeated multiplication.
42 = 4 × 4 = 16
The times node gets 4 from the left and 16 from the right. Four times 16 is 64.
4 × 16 = 64
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
cd svg-generator python3 -m svgmath render order-of-operations-tree --out /tmp/order-of-operations-tree
Source: svgmath/diagrams/order_of_operations.py