ch10 carrano java - com sci gate€¦ · ch10_carrano_java.ppt author: lowelll created date:...
TRANSCRIPT
Data Abstraction and Problem Solving with JAVA Walls and MirrorsFrank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Data Abstraction and Problem Solving with JAVA:Data Abstraction and Problem Solving with JAVA:Walls and MirrorsWalls and Mirrors
CarranoCarrano / / PrichardPrichard
TreesTrees
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.1Figure 10.1A general tree
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.2Figure 10.2A subtree of the tree in Figure 10.1
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.3Figure 10.3a) An organization chart; b) a family tree
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.4Figure 10.4Binary trees that represent algebraic expressions
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.5Figure 10.5A binary search tree of names
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.6Figure 10.6Binary trees with the same nodes but different heights
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.7Figure 10.7A full binary tree of height 3
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.8Figure 10.8A complete binary tree
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.9Figure 10.9Traversals of a binary tree: a) preorder; b) inorder; c) postorder
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.10aFigure 10.10aa) A binary tree of names
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.10bFigure 10.10bb) its array-basedimplementations
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.11Figure 10.11Level-by-level numbering of a complete binary tree
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.12Figure 10.12An array-based implementation of the complete binary tree in Figure 10-11
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.13Figure 10.13A reference-based implementation of a binary tree
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.14Figure 10.14Contents of the implicit stack as treeNode progresses through a given treeduring a recursive inorder traversal
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.15Figure 10.15Traversing a) the left and b) the right subtrees of 20
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.16Figure 10.16Avoiding returns to nodes B and C
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.17Figure 10.17A binary search tree
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.18aFigure 10.18aBinary search trees with the same data as in Figure 10-17
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.18bFigure 10.18bBinary search trees with the same data as in Figure 10-17
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.18cFigure 10.18cBinary search trees with the same data as in Figure 10-17
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.19Figure 10.19An array of names in sorted order
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.20Figure 10.20Empty subtree where search terminates
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.21a and 10.21bFigure 10.21a and 10.21ba) Insertion into an empty tree; b) search terminates at a leaf
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.21cFigure 10.21cc) insertion at a leaf
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.22Figure 10.22a) N with only a left child—N can be either the left or right child of P; b) afterdeleting node N
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.23Figure 10.23N with two children
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.24Figure 10.24Not any node will do
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.25Figure 10.25Search key x can be replaced by y
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.26Figure 10.26Copying the item whose search key is the inorder successor of N ’s search key
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.27Figure 10.27Recursive deletion of node N
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.28Figure 10.28A maximum-height binary tree with seven nodes
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.29Figure 10.29Binary trees of height 3
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.30Figure 10.30Counting the nodes in a full binary tree of height h
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.31Figure 10.31Filling in the last level of a tree
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.32Figure 10.32The order of the retrieval, insertion, deletion, and traversal operations for thereference-based implementation of the ADT binary search tree
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.33Figure 10.33a) A binary search tree bst; b) the sequence of insertions that result in this tree
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.34Figure 10.34A full tree saved in a file by using inorder traversal
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.35Figure 10.35A tree of minimum height that is not complete
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.36Figure 10.36A general tree
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.37Figure 10.37A reference-based implementation of the general tree in Figure 10.36
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.38Figure 10.38The binary tree that Figure 10-37 represents
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.39Figure 10.39An implementation of the n-ary tree in Figure 10.36
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.40Figure 10.40A tree for Self-Test Exercises 1, 3, 7, and 11 and for Exercises 6 and 11
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.41Figure 10.41An array for Self-Test Exercise 9
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.42Figure 10.42A tree for Self-Test Exercise 10 and for Exercise 2a
Data Abstraction and Problem Solving with JAVA Walls and Mirrors; Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley
Figure 10.43Figure 10.43A binary search tree for Exercise 3