# Lecture Notes for CS 245 - Data Struct & Algorithms with Galles at University of San Francisco (USF)

## Notes Information

 Material Type: Class Note Professor: Galles Class: CS 245 - Data Struct & Algorithms Subject: Computer Science University: University of San Francisco (CA) Term: Summer III 2009 Keywords: On the RightOn the LeftIndentationInorder TraversalBinary Search

## Sample Document Text

CS245-2009S-07 Tree Operations 1 07-0: Binary Tree Definition class Node { Node() { } Node(Comparable elem) { element_ = element; } Node(Object element, Node left, Node right) { element_ = element; left_ = left; right_ = right; } /* Access methods on next slide */ private Node left_; private Node right_; private Comparable element_; } 07-1: Binary Tree Access Methods Node left() { void setLeft(Node left) { return left_; left_ = left; } } Node right() { void setRight(Node right) { return right_; right_ = right; } } Comparable element() { return element_; } void setElement(Comparable element) { element_ = element; } 07-2: Tree Operations - Height . Returns the height of the tree . (Length of the path to the deepest leaf) + 1 CS245-2009S-07 Tree Operations 2 Height = 5 Height = 6 07-3: Tree Operations - Height int height(Node tree) { if (tree == null) return 0; return 1 + MAX(height(tree.left()), height(tree.right())); } 07-4: Tree Operations - NumNodes . Returns the nu...

## Related Documents

On the Right Notes
Inorder Traversal Notes
Display Property Notes
On the Left Notes
Binary Search Notes
On the Right Notes
Binary Search Notes
On the Left Notes
On the Right Notes
Positioning Notes
On the Left Notes
On the Left Notes
On the Left Notes
On the Right Notes
On the Right Notes
On the Left Notes