logo

AQA A-Level Computer Science practice

An expression tree has / as its root. Its left child is - and its right child is +. The - node has leaves x and y. The + node has leaves z and 2. Trace a post-order traversal and write the resulting postfix expression. Explain why post-order is suitable for producing a postfix expression from an expression tree, and give one other specified use of post-order traversal.

Try the question first, then check the answer and practise the same topic again.

At a glance

Question

Type

practice

Style

Topic

Tree-traversal

Exam-style question

Try this first

An expression tree has / as its root. Its left child is - and its right child is +. The - node has leaves x and y. The + node has leaves z and 2. Trace a post-order traversal and write the resulting postfix expression. Explain why post-order is suitable for producing a postfix expression from an expression tree, and give one other specified use of post-order traversal.

Answer and explanation

Concise answer

The post-order traversal is x, y, -, z, 2, +, /.

Why this is correct

The left subtree is visited first, producing x y -. The right subtree is then visited, producing z 2 +. Finally, the root operator / is visited. This gives x y - z 2 + /, with each operator appearing after its corresponding subexpressions.

Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions