“Create a binary expression tree for (a × b) + (c − (d ÷ (e + f))), with + as the root, × on the left and − on the right.”
図の背後にある意思決定を読み解く。
Put the outermost addition at the root.
Give every operator a left and right child.
Group multiplication and subtraction before addition.
Use this tree to explain parsing and expression evaluation.
よくある質問
What are the leaves in an expression tree?
Leaves are operands such as numbers, variables or constants.
Why use a binary tree for an expression?
Binary operators naturally have a left operand and a right operand.
How is the root chosen?
It is the outermost operation, performed after its two subexpressions.