BINARY TREES in Java
BINARY TREES Data Matrix ECC200 Recognizer In Java Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications. Generating Data Matrix In Java Using Barcode generation for Java Control to generate, create ECC200 image in Java applications. 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ECC200 Scanner In Java Using Barcode decoder for Java Control to read, scan read, scan image in Java applications. Barcode Printer In Java Using Barcode printer for Java Control to generate, create barcode image in Java applications. for (it = tree.new InOrder(); it.hasNext(); ) { System.out.print(it.next() + " "); } System.out.print("\nPostOrder Traversal: "); for (it = tree.new PostOrder(); it.hasNext(); ) { System.out.print(it.next() + " "); } System.out.print("\nLevelOrder Traversal: "); for (it = tree.new LevelOrder(); it.hasNext(); ) { System.out.print(it.next() + " "); } System.out.println(); } } Bar Code Decoder In Java Using Barcode scanner for Java Control to read, scan read, scan image in Java applications. Painting Data Matrix ECC200 In C# Using Barcode encoder for Visual Studio .NET Control to generate, create Data Matrix 2d barcode image in VS .NET applications. The output is: Drawing Data Matrix In VS .NET Using Barcode maker for ASP.NET Control to generate, create ECC200 image in ASP.NET applications. Generate DataMatrix In VS .NET Using Barcode drawer for VS .NET Control to generate, create Data Matrix 2d barcode image in Visual Studio .NET applications. tree = [A, B, D, G, E, C, PreOrder Traversal: A B InOrder Traversal: D G PostOrder Traversal: G D LevelOrder Traversal: A B F, H, D G E B E A E B H C D E I] C F H F I F F G H I C H I C A I DataMatrix Encoder In VB.NET Using Barcode maker for .NET Control to generate, create Data Matrix 2d barcode image in Visual Studio .NET applications. Generating USS Code 128 In Java Using Barcode encoder for Java Control to generate, create USS Code 128 image in Java applications. Each of the four iterators traverses the tree according to the algorithm that it implements.
Encoding GS1128 In Java Using Barcode generator for Java Control to generate, create EAN / UCC  14 image in Java applications. Encode Code 128 Code Set B In Java Using Barcode creator for Java Control to generate, create Code 128 Code Set A image in Java applications. FORESTS A forest is a sequence of disjoint ordered trees. EXAMPLE 11.25 A Forest
Delivery Point Barcode (DPBC) Creation In Java Using Barcode encoder for Java Control to generate, create USPS POSTal Numeric Encoding Technique Barcode image in Java applications. Encoding Code128 In Java Using Barcode encoder for BIRT reports Control to generate, create Code128 image in BIRT reports applications. Figure 11.23 shows a forest that consists of three trees.
Code 3/9 Scanner In None Using Barcode decoder for Software Control to read, scan read, scan image in Software applications. Print European Article Number 13 In .NET Using Barcode creation for VS .NET Control to generate, create GS1  13 image in Visual Studio .NET applications. Figure 11.23 A forest
UPC Code Encoder In None Using Barcode creator for Software Control to generate, create UPCA Supplement 5 image in Software applications. Code39 Reader In .NET Framework Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications. The following algorithm shows how a forest can be represented by a single binary tree. Algorithm 11.8 The Natural Mapping of a Forest into a Binary Tree 1. Map the root of the first tree into the root of the binary tree. 2. If node X maps into X' and node Y is the first child of X, then map Y into the left child of X'. 3. If node X maps into X' and node Z is the sibling of X, then map Z into the right child of X'. The roots of the trees themselves are considered siblings. Generating Bar Code In None Using Barcode drawer for Software Control to generate, create bar code image in Software applications. Generate ECC200 In Java Using Barcode generation for Android Control to generate, create Data Matrix image in Android applications. BINARY TREES
[CHAP. 11
EXAMPLE 11.26 Mapping a Forest into a Binary Tree
Figure 11.24 is the mapping of the forest shown in Example 11.25. For example, in the original forest, C has oldest child F and next sibling D. In the corresponding binary tree, C has left child F and right child D. Figure 11.24 The natural mapping of a forest into a binary tree
Review Questions
11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 How many leaf nodes does the full binary tree of height h = 3 have How many internal nodes does the full binary tree of height h = 3 have How many nodes does the full binary tree of height h = 3 have How many leaf nodes does a full binary tree of height h = 9 have How many internal nodes does a full binary tree of height h = 9 have How many nodes does a full binary tree of height h = 9 have What is the range of possible heights of a binary tree with n = 100 nodes Why is there no inorder traversal for general trees True or false: a. If all of its leaves are at the same level, then the binary tree is full. b. If the binary tree has n nodes and height h, then h lg n . c. A binary tree cannot have more than 2d nodes at depth d. d. If every proper subtree of a binary tree is full, then the tree itself must also be full. Problems
11.1 11.2 For each of the binary trees in Figure 11.25 on page 221, draw the equivalent version that satisfies the second definition, namely that every internal node has two children. Give the order of visitation of the binary tree shown in Figure 11.26 using the specified traversal algorithm: a. the level order traversal b. the preorder traversal c. the inorder traversal d. the postorder traversal CHAP. 11] BINARY TREES
Figure 11.25 Binary trees
Figure 11.26 A binary tree
Figure 11.27 A binary tree
Give the order of visitation of the binary tree of size 10 shown in Example 11.1 on page 201 using: a. the level order traversal b. the preorder traversal c. the inorder traversal d. the postorder traversal Give the order of visitation of the binary tree shown in Figure 11.27 using: a. the level order traversal b. the preorder traversal c. the inorder traversal d. the postorder traversal BINARY TREES
[CHAP. 11
11.5 11.6 11.7 11.8 Show the array that is obtained by using the natural mapping to store the binary tree shown in Problem 11.1. Show the array that is obtained by using the natural mapping to store the binary tree shown in Example 11.1 on page 201. Show the array that is obtained by using the natural mapping to store the binary tree shown in Problem 11.4. If the nodes of a binary tree are numbered according to their natural mapping, and the visit operation prints the node s number, which traversal algorithm will print the numbers in order Draw the expression tree for a*(b + c)*(d*e + f). 11.10 Write the prefix and the postfix representations for the expression in Problem 11.8. 11.11 Draw the expression tree for each of the prefix expressions given in Problem 5.2 on page 111. 11.12 Draw the expression tree for each of the infix expressions given in Problem 5.4 on page 111. 11.13 Draw the expression tree for each of the postfix expressions given in Problem 5.6 on page 111. 11.14 Draw the expression tree for the expression a*(b + c)*(d*e + f). 11.15 What are the bounds on the number n of nodes in a binary tree of height 4 11.16 What are the bounds on the height h of a binary tree with 7 nodes 11.17 What form does the highest binary tree have for a given number of nodes 11.18 What form does the lowest binary tree (i.e., the least height) have for a given number of nodes 11.19 Verify the recursive definition of binary trees (page 200) for the binary tree shown in Figure 11.28. 11.20 Draw all 42 binary trees of size n = 5. 11.21 How many different binary trees of size n = 6 are there 11.22 Derive a recurrence relation for the number f(n) of binary trees of size n.

