Draw three ordered trees that are isomorphic to the ordered binary tree at the top left of Figure 5.20. That is, you should be able to transform the four trees to one another by exchanging children.
Assume that trees contain items for which equals() is implemented. Write a recursive program that deletes all the leaves in a binary tree with items equal to a given item (see Program 5.5).
Binary trees are equivalent to binary strings that have one more 0 bit than 1 bit, with the additional constraint that, at any position k, the number of 0 bits that appear strictly to the left of k is no larger than the number of 1 bits strictly to the left of k. A binary tree is either a 0 or two such strings concatenated together, preceded by a 1. Draw the binary tree that corresponds to the string:
1 1 1 0 0 1 0 1 1 0 0 0 1 0 1 1 0 0 0.
Give upper and lower bounds on the height of an M-ary tree with N internal nodes.
Give upper and lower bounds on the internal path length of an M-ary tree with N internal nodes.
Give preorder, inorder, postorder, and level-order traversals of the following binary trees:
Write a program that counts the leaves in a binary tree.
Write a program that counts the number of nodes in a binary tree that have one external and one internal child.
Write a recursive program that computes the internal path length of a binary tree, using Definition 5.6.
Write a recursive program that computes the internal path length of a binary tree in time proportional to the number of nodes in the tree.
How many different ways are there to represent the free tree in Figure 5.20 as an ordered tree?
Write a program to determine whether or not two arrays of N integers between 0 and N - 1 represent isomorphic unordered trees, when interpreted (as in Chapter 1) as parent-child links in a tree with nodes numbered between 0 and N - 1. That is, your program should determine whether or not there is a way to renumber the nodes in one tree such that the array representation of the one tree is identical to the array representation of the other tree.
Write a program to determine whether or not two binary trees represent isomorphic unordered trees.
Prove that, if a connected graph of N nodes has the property that removing any edge disconnects the graph, then the graph has N - 1 edges and no cycles.
Show that if the levels of the external nodes in a binary tree differ by a constant, then the height is O log N .
Give a nonrecursive implementation of inorder traversal.
Give a nonrecursive implementation of postorder traversal.
Write a program that takes as input the preorder and inorder traversals of a binary tree and that produces as output the level-order traversal of the tree.
Back to the list of assignments.