0% found this document useful (0 votes)
105 views4 pages

Name: Student No. Group: - Expression Tree - : Csc248 - Fundamentals of Data Structures Tree: Class Exercise

An expression tree is a binary tree that represents an arithmetic expression, with operators as interior nodes and operands as leaf nodes. Expression trees can be built from prefix or postfix notation by evaluating the notation from left to right or right to left respectively, with operators as roots and operands as leaves, and opening left or right branches first. The document provides examples of building expression trees from infix, prefix, and postfix notations.

Uploaded by

Kimpiz IT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views4 pages

Name: Student No. Group: - Expression Tree - : Csc248 - Fundamentals of Data Structures Tree: Class Exercise

An expression tree is a binary tree that represents an arithmetic expression, with operators as interior nodes and operands as leaf nodes. Expression trees can be built from prefix or postfix notation by evaluating the notation from left to right or right to left respectively, with operators as roots and operands as leaves, and opening left or right branches first. The document provides examples of building expression trees from infix, prefix, and postfix notations.

Uploaded by

Kimpiz IT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CSC248 - FUNDAMENTALS OF DATA STRUCTURES

TREE: CLASS EXERCISE

NAME : MUHAMMAD NUR HAFIZ BIN MOHD ROSLIM

STUDENT NO. 2018663062

GROUP : RCS1104C

-- EXPRESSION TREE --

★ Expression tree is a binary tree that represents an arithmetic expression


★ In an expression tree, each operator is an interior node. Operands are in the leaf nodes.
★ Expression tree can be built with prefix and postfix notation only. Any infix expression must be
converted to prefix/postfix expression in order to build the expression tree
★ Prefix or postfix expression will produce the same expression tree if it comes from the same infix
expression

When given a prefix expression:

1) Evaluate prefix expression from LEFT to RIGHT


2) Any operator must be at the root & any operand must be at the leaf
3) Always open the LEFT branch first until more branches can be opened. Then open the RIGHT
branch

When given a postfix expression:

1) Evaluate postfix expression from RIGHT to LEFT


2) Any operator must be at the ROOT, and any operand must be at the leaf
3) Always open the RIGHT branch first until no more branches can be opened. Then open the
LEFT branch

-- QUESTION #1 --
CSC248 - FUNDAMENTALS OF DATA STRUCTURES
TREE: CLASS EXERCISE

Given the following infix expression, build its expression tree.

(A + B) * C * (D - E)

Hint: Convert the infix expression to prefix expression.

Prefix: * * + A B C – D E

-- QUESTION #2 --

Given the following prefix expression, draw the expression tree:

+A*-BC$D*EF
CSC248 - FUNDAMENTALS OF DATA STRUCTURES
TREE: CLASS EXERCISE

-- QUESTION #3 --

Given the following infix expression, build its expression tree.

(A + B) * C * (D - E)

Hint: Convert the infix expression to postfix expression.

Postfix: A B + C * D E - *

-- QUESTION #4 --

(a) Given the following postfix expression, draw the expression tree:

ABC-DEF*$*+

(b) Given that: A = 5, B = 3, C = 4, D = 6, E = 1 and F = 2, evaluate the given postfix expression.

-- QUESTION #5 --
CSC248 - FUNDAMENTALS OF DATA STRUCTURES
TREE: CLASS EXERCISE

Traverse the expression tree in:


I. Pre-order traversal
II. In-order traversal
III. Post-order traversal

You might also like