21-binary_search_tree_2

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

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

View Full Document Right Arrow Icon
CSE 143 Lecture 21 Binary Search Trees, continued read 17.3 slides created by Marty Stepp http://www.cs.washington.edu/143/
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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!)
Background image of page 4
Image of page 5
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 Right Arrow Icon
Ask a homework question - tutors are online