ExpressionTrees-14 - Simplified Version of Expression Trees...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Simplified Version of Expression Trees In the text, expression trees for arbitrary statements are discussed. For now, I will present expression trees for simple arithmetic expressions, those similar to the ones we looked at when studying stacks. Consider the following infix expression: ((3 + 8)*2 - 10) / ((7 - 5)*2 - 1) Noting that we could store a simple expression such as a * b in a binary tree as follows: * / \ a b We could build an expression tree under the same principle (root node stores the operator, the left child node stores the first operand and the right child node stores the second operand.) Clearly, in order to properly build this tree, all operands must be stored at leaf nodes. Here is our resulting tree: / / \ - - / \ / \ * 10 * 1 / \ / \ + 2 - 2 / \ / \ 3 8 7 5
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Evaluating an Expression Stored in an Expression Tree Ultimately, this boils down to the way we defined the expression tree: 1) Determine the value(V L ) of the left subtree 2) Determine the value(V R ) of the right subtree
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/22/2010 for the course EECS COP 3502 taught by Professor Guha during the Spring '09 term at University of Central Florida.

Page1 / 6

ExpressionTrees-14 - Simplified Version of Expression Trees...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online