Lab VII - COSC 215
Lab VII - COSC 215
b. Method isPerfect that checks whether the tree is perfect. A perfect binary tree is
a special type of binary tree in which all the leaf nodes are at the same depth, and all
non-leaf nodes have two children. In simple terms, this means that all leaf nodes are
at the maximum depth of the tree, and the tree is completely filled with no gaps. A
perfect tree of height h has total nodes = 2h – 1
2
b. Construct the tree T2 containing the following characters values:
Sample output
Constructing T1
...
Preorder T1...
1 2 4 5 3 6 7
Inorder T1...
4 2 5 1 6 3 7
Postorder T1...
4 5 2 6 7 3 1
T1 size: 7
T1 Number of leaves: 4
T1 Height: 3
T1 is balanced? Yes
T1 is perfect? Yes
Constructing T2
...
Preorder T2...
A B F C D E
Inorder T2...
3
F B A D C E
Postorder T2...
F B D E C A
T2 size: 6
T2 Number of leaves: 3
T2 Height: 3
T2 is balanced? Yes
T2 is perfect? No
Constructing T3
...
Preorder T3...
A B F G C D E
Inorder T3...
G F B A D C E
Postorder T3...
G F B D E C A
T3 size: 7
T3 Number of leaves: 3
T3 Height: 4
T3 is balanced? No
T3 is perfect? No
Producing T1
...
Preorder...
31 3 17 8 5 23 20 28 62 51 44 40 88
Inorder...
3 5 8 17 20 23 28 31 40 44 51 62 88
Postorder...
5 8 20 28 23 17 3 40 44 51 88 62 31
Minimum of T1 is 3
18 is found in T1? No
44 is found in T1? Yes
Enter an integer key: 19
The count of keys, of T1, > 19 is: 9
Removing root of T1...
Preorder...
40 3 17 8 5 23 20 28 62 51 44 88
Producing T2
...
Preorder...
this is a bst and cool of it strings quick
Inorder...
a and bst cool is it of quick strings this
Postorder...
and cool bst a it quick strings of is this
Minimum of T2 is a
"warm" is found in T2? No
"cool" is found in T2? Yes
Enter a string key: binary
The count of keys, of T2, > binary is: 8
Removing root of T2...
Preorder...
is a bst and cool of it strings quick