# 27 - CMPSCI 187 Programming With Data Structures Lecture#27...

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

CMPSCI 187: Programming With Data Structures Lecture #27: Expression Trees 18 November 2011

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

View Full Document
Expression Trees • L&C’s BinaryTreeADT Interface • Some Uses of Binary Trees • Review of LinkedBinaryTree and ArrayBinaryTree Classes • Expression Trees and the ExpressionTree Class • Evaluating an Expression Tree • The PostFx Evaluator Revisited
L&C’s BinaryTreeADT Interface • Just as with lists, we have an ADT defning operations that are common to all binary trees. For each type o± binary tree, we can then extend this inter±ace to add the appropriate new operations. • Note that this inter±ace has no operations to change the tree, because each extension will have its own methods to add or remove nodes. public interface BinaryTreeADT<T> { public T getRoot ( ); public boolean isEmpty ( ); public int size ( ); public boolean contains (T target); public T find (T target); public String toString ( ); public Iterator<T> interatorInOrder ( ); public Iterator<T> interatorPreOrder ( ); public Iterator<T> interatorPostOrder ( ); public Iterator<T> interatorLevelOrder ( );}

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

View Full Document
Some Uses Of Binary Trees • A binary tree can be used to implement an ordered list more efFciently than an array. Next week we will see binary search trees , binary trees where every node contains an element from some comparable class. If x is the element at a node n, we make sure that all the nodes in the subtree under n’s left child are less than n, and all the nodes in the right subtree are greater than n. We can then insert or delete an element by going down the tree to Fnd the right place for the action, and the edit to the tree does not require shifting. • If the tree is balanced, this will be O(log n) time instead of O(n) time for the
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/22/2011 for the course COMPSCI 187 taught by Professor Barrington during the Fall '11 term at UMass (Amherst).

### Page1 / 9

27 - CMPSCI 187 Programming With Data Structures Lecture#27...

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

View Full Document
Ask a homework question - tutors are online