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

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

CMPSCI 187: Programming With Data Structures Lecture #29: More on Binary Search Trees 23 November 2011

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

View Full Document
More on Binary Search Trees • Implementing an Ordered List • Comparing Linked and Tree Implementations • How to Keep a Tree Balanced • Ordinary Right and Left Rotations • Compound Rotations: RightLeft and LeftRight • AVL Trees (Basic Idea Only) • Red/Black Trees (Basic Idea Only)
Implementing an Ordered List • This is actually pretty anticlimactic. For each of the adding, removing, and ±nding list operations we have a corresponding operation already in LinkedBinarySearchTree<T> . The operations contains , isEmpty , and size are just inherited directly from LinkedBinarySearchTree<T> or its ancestor classes with the same names, so they don’t appear in the code. public class BSTList<T> extends LinkedBinarySearchTree<T> implements ListADT<T>, OrderedListADT<T>, Iterable<T> { public BSTList ( ) {super( );} public void add (T element) {addElement (element);} public T removeFirst ( ) {return removeMin( );} public T removeLast ( ) {return removeMax( );} public T remove (T element) {return removeElement (element);} public T first ( ) {return findMin( );} public T last ( ) return findMax( );} public Iterator<T> iterator( ) {return iteratorInOrder( );}}

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

View Full Document
Comparing Linked and Tree Implementations • The linked list implementation of an ordered list did some things in O(1) time: removeFirst , first , isEmpty , and size . (With a doubly linked list we could also perform removeLast and last in O(1) time.) The other operations were all O(n), because in the worst case they involved a linear search of the whole list. • If
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 9

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

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

View Full Document
Ask a homework question - tutors are online