0% found this document useful (0 votes)
4 views1 page

Lab 05 DSA

Uploaded by

Đức Triển
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Lab 05 DSA

Uploaded by

Đức Triển
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Lab 5 - Binary Tree

Problem 1. An expression can be represented by a binary tree in which:


− Each leaf node contains a single operand.
− Each non-leaf node contains a single binary operator.
− The left and right sub-trees of an operator node represent sub-expressions that
must be evaluated before applying the operator at the root of the sub-trees.
For example, the infix expression ((8 - 5) * ((4 + 2) / 3)) can be represented as the
following binary tree:

Write a program to create the binary tree above and perform the following operations
discussed:
a) Print out the expression in the prefix form (pre-order trversal).
b) Print out the expression in the infix form (in-order trversal).
c) Print out the expression in the postfix form (post-order trversal).
d) Compute the value of the postfix expression.
Suggestion:
You should reuse the solution to Problem 1 in Lab 3.

You might also like