L08_bst_supp

L08_bst_supp - COMP 152 Binary Search Tree 1 H.O.#8...

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

View Full Document Right Arrow Icon
COMP 152 Binary Search Tree 1 H.O.#8 supplement Spring 2010 Gary Chan Binary Tree Terminology A node that has one or two children is called an internal node . The two children of a node are siblings of each other. For example, left( x ) is the left sibling of right( x ) and right( x ) is the right sibling of left( x ). A node usually contains a data ±eld as well to store some value. Subtree: pick any node x , then x and its de- scendants form a subtree, which we call the subtree rooted at x . at x subtree rooted x
Background image of page 1

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

View Full DocumentRight Arrow Icon
COMP 152 Binary Search Tree 2 Expression Trees Binary trees that represent arithmetic ex- pressions One application of expression trees is in the generation of optimal computer code to eval- uate an expression a b c d * / + (a) ( a * b ) + ( c / d ) a b + c + d + (b) (( a + b ) + c ) + d ) a x y b c a - + + * + * / (c) (( - a ) + ( x + y )) / (( +b ) * ( c * a )) Figure 8.5 Expression trees
Background image of page 2
COMP 152 Binary Search Tree 3 Formation of Expression Tree 1. Start from a postFx expression If the input is in inFx, convert it to post- Fx Frst using stack 2. Initialize a stack whose data is pointer to character 3. Push operand into the stack (i.e., make the pointer pointing to the operand) 4. When an operator is encountered: (a) Create a binary node with the operator
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

L08_bst_supp - COMP 152 Binary Search Tree 1 H.O.#8...

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

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