ExpressionTrees-14

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

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

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

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

View Full Document
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
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
Ask a homework question - tutors are online