14. BinarySearchTrees_outside

W external nodes do not store items an inorder

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

View Full Document Right Arrow Icon
w ) External nodes do not  store items An inorder traversal of a  binary search trees  visits the keys in  increasing order 6 9 2 4 1 8 © 2010 Goodrich, Tamassia
Background image of page 5

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

View Full Document Right Arrow Icon
Binary Search Trees 6 Search To search for a key  k , we  trace a downward path  starting at the root The next node visited  depends on the  comparison of  k  with the  key of the current node If we reach a leaf, the key  is not found Example:  get (4): Call TreeSearch(4,root) The algorithms for  floorEntry  and  ceilingEntry  are similar Algorithm TreeSearch ( k , v ) if v.isExternal () return v if k < v.key () return TreeSearch ( k , v.left ()) else if k = v.key () return v else { k v.key () } return TreeSearch ( k , v.right ()) 6 9 2 4 1 8 < = © 2010 Goodrich, Tamassia
Background image of page 6
Binary Search Trees 7 Insertion To perform operation  put (k,  o), we search for key k  (using TreeSearch) Assume k is not already in  the tree, and let w be the  leaf reached by the search We insert k at node w and  expand w into an internal  node Example: insert 5 6 9 2 4 1 8 6 9 2 4 1 8 5 < w w © 2010 Goodrich, Tamassia
Background image of page 7

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

View Full Document Right Arrow Icon
Binary Search Trees 8 Deletion To perform operation  erase ( k ), we search for key 
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page5 / 10

w External nodes do not store items An inorder traversal of...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online