Click on any exercise below to see the source code, program output and explanation of the code.  The exercises in this section make use of trees. A tree is a non-empty collection of vertices (nodes) and edges that satisfies certain requirements. A vertex can have a name, as well as carry other information. An edge connects two vertices.

Available Exercises

Exercise 7.1. Write a program to read integers, store them in a binary tree, display the content of the tree, deletes the tree and exits. Decide in what order the integers are added to the tree and develop a convenient way for displaying the tree.

Exercise 7.2. Write a program which, given the root pointer of a binary tree returns the height of the tree (height = number of levels).

Exercise 7.3. Write a recursive function which, given the root pointer of a binary tree returns the number of leaves of the tree.