CSE 2320 - Assignments

Not Graded Practice for Assignment 7


Practice Question 1

(This is Problem 5.58 from the textbook).

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.


Practice Question 2

(This is Problem 5.59 from the textbook).

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).


Practice Question 3

(This is Problem 5.62 from the textbook).

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.


Practice Question 4

(This is Problem 5.69 from the textbook).

Give upper and lower bounds on the height of an M-ary tree with N internal nodes.


Practice Question 5

(This is Problem 5.70 from the textbook).

Give upper and lower bounds on the internal path length of an M-ary tree with N internal nodes.


Practice Question 6

(This is Problem 5.79 from the textbook).

Give preorder, inorder, postorder, and level-order traversals of the following binary trees:


Practice Question 7

(This is Problem 5.86 from the textbook).

Write a program that counts the leaves in a binary tree.


Practice Question 8

(This is Problem 5.87 from the textbook).

Write a program that counts the number of nodes in a binary tree that have one external and one internal child.


Practice Question 9

(This is Problem 5.88 from the textbook).

Write a recursive program that computes the internal path length of a binary tree, using Definition 5.6.


Practice Question 10

(This is Problem 5.90 from the textbook).

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.


(Challenge) Practice Question 11

(This is Problem 5.57 from the textbook).

How many different ways are there to represent the free tree in Figure 5.20 as an ordered tree?


(Challenge) Practice Question 12

(This is Problem 5.64 from the textbook).

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.


(Challenge) Practice Question 13

(This is Problem 5.65 from the textbook).

Write a program to determine whether or not two binary trees represent isomorphic unordered trees.


(Challenge) Practice Question 14

(This is Problem 5.67 from the textbook).

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.


(Challenge) Practice Question 15

(This is Problem 5.72 from the textbook).

Show that if the levels of the external nodes in a binary tree differ by a constant, then the height is O log N .


(Challenge) Practice Question 16

(This is Problem 5.82 from the textbook).

Give a nonrecursive implementation of inorder traversal.


(Challenge) Practice Question 17

(This is Problem 5.83 from the textbook).

Give a nonrecursive implementation of postorder traversal.


(Challenge) Practice Question 18

(This is Problem 5.84 from the textbook).

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.