Graph Theory Lessons

graphic graphic graphicLesson 13: Trees


For this lesson you will need to use the geometric series. Consult your calculus books if you need to. A tree is a connected graph that has no circuits. In the program select Full n-ary Tree. When asked for n, input 2 and when asked for the number of levels input 3. You should get a graph that looks like figure 19
graphic
Fig. 19, A full binary tree with 3 levels.

In a full n-ary tree we have a special vertex in the tree called the root. The root has edges to n other vertices called its children. The children of the root are said to be on level 1. If we have h levels, then for 0 < i < h, each vertex on level i has n children of its own which are on level i+1. The vertices on the last level, h, have no children and are called leaves. The vertices that are not leaves are said to be internal vertices. The root counts as an internal vertex. In figure 19 the root is vertex 1 and n=2. The internal vertices are vertices 1 through 7 and the leaves are vertices 8 through 15. When n is 2, as in our example, the tree is called a binary tree so figure 19 is a full binary tree with 3 levels . This tree has 8 leaves.
  1. By looking at the statistics, find the number of vertices and the number of edges in a full binary tree with
    • 2 levels
    • 3 levels
    • 4 levels.
  2. Note that the number of vertices in a full binary tree with h levels is 1+2+22+23+...+2h. What is the sum of this series?
  3. How many leaves does a full binary tree with h levels have? How many leaves does a full binary tree with 25 levels have?
  4. How many internal vertices does a full binary tree with h levels have?
    An n-ary tree with n=3 is called a ternary tree. Figure 20 shows a full ternary tree with 3 levels.
    graphic
    Fig. 20. A full ternary tree with 3 levels.

  5. How many vertices will a full ternary tree with h levels have?
    • How many leaves will a full ternary tree with 25 levels have?
    • How many leaves will a full n-ary tree with h levels have?
  6. Note that in any tree, every vertex has an edge joining it to its parent (except the root which has no parent). How many edges in total should a tree with n vertices have?
  7. Use the program to decide which of the trees in question 1) are bipartite.
  8. If a graph is a tree, what is its chromatic number?
  9. If an n x n matrix is the adjacency matrix of a tree, how many zeros and how many ones should it have?
    Recall (see your textbook if necessary) that in a depth first search we go to the next level at the earliest opportunity while in a breadth first search we search all the vertices at a given level before going to the next level. Get the graph in figure 19 again and choose Find then Search and Depth First. When asked which vertex to find input 11. You will see the edges used in a depth first search appear first in green , then in red etc. You can use the buttons at the bottom left corner to speed up or slow down the graphics. Do the same for a breadth first search.
  10. Make a table with three columns labeled "Vertex", "Depth First" and "Breadth First" and for each vertex in the graph of figure 19 find how many steps it takes to find it using the two search methods.
  11. Which vertices in this graph (fig. 19) require the same number of steps when you do a breadth first search as when you do a depth first search?
  12. By adding up the entries in the columns and dividing by 15, find the average number of steps needed for
    • a depth first search
    • a breadth first search

  13. What is the the average number of steps needed to search a tree with n vertices using either method?
  14. Suppose you have a full ternary tree with 25 levels (don't even think of drawing it) and vertices labeled left to right like in figure 20.
    • What level is vertex 50 in?
    • What are the labels of the three children of vertex 50?
    • What is the label of the parent of vertex 50?

Answers

e-mail: C. Mawata
graphic graphic graphic
© C. Mawata