L08_bst_supp

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

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

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

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

View Full Document
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
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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/25/2010 for the course COMP COMP152 taught by Professor D.y.yeung during the Spring '10 term at HKUST.

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