![]() |
|
![]() |
|||||||||||
![]() |
![]() |
||||||||||||
Next Monday 24: online quiz (writing methods) Wed Dec. 3: Exam 3 (all written) ************************************** BINARY SEARCH TREES ************************************** balanced - height of left tree ~= height of right tree (for all nodes; off by one) height - either start at level 0, or at 1. (null tree is either 0 or -1) traversal types inorder > display returns straight line preorder > display returns exact same tree postorder > display returns different tree // For use by countEvens() private int countR(Node top) { if (top == null) return 0; L = countR(top, left); R = countR(top, right); if ((top.data%2) == 0) return L + R + 1; else return L + R; -delete a leaf with 2 children by redefining the greatest left leaf (or smallest right leaf) as the subtree's new root. -delete a leaf with no children by pointing its parent to null. -delete a leaf with one child by pointing its parent to the child. (woo! getting out of class early!) Post a comment in response: |
| © 2002-2008. Blurty Journal. All rights reserved. |