21-binary_search_tree_2

# 21-binary_search_tree_2 - CSE 143 Lecture 21 Binary Search...

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

CSE 143 Lecture 21 Binary Search Trees, continued read 17.3 slides created by Marty Stepp http://www.cs.washington.edu/143/

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

View Full Document
2 Binary search trees binary search tree ("BST"): a binary tree that is either: –emp ty ( null ), or – a root node R such that: • every element of R's left subtree contains data "less than" R's data, • every element of R's right subtree contains data "greater than" R's, • R's left and right subtrees are also binary search trees. • BSTs store their elements in sorted order, which is helpful for searching/sorting tasks. 91 60 87 29 55 42
3 Exercise • Add a method add to the IntTree class that adds a given integer value to the tree. Assume that the elements of the IntTree constitute a legal binary search tree, and add the new value in the appropriate place to maintain ordering. •tree.add(49) ; 91 60 87 29 55 42 -3 overall root 49

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

View Full Document
4 The incorrect solution public class SearchTree { private IntTreeNode overallRoot; // Adds the given value to this BST in sorted order. // (THIS CODE DOES NOT WORK PROPERLY!)
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/04/2011 for the course CSE 143 taught by Professor Sr during the Spring '08 term at University of Washington.

### Page1 / 12

21-binary_search_tree_2 - CSE 143 Lecture 21 Binary Search...

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

View Full Document
Ask a homework question - tutors are online