Lex 7: Trees

  1. Consider tree T1:

                      root: a
             children of a: q _
             children of q: p c
             children of c: b e
             children of b: _ d
            

    Show the contents of a one-array implementation of the tree. Start with element 0 of the array. Put exactly one space between array elements. If an array element is empty indicate it with an underscore, i.e., "_". All letters should be lowercase.

  2. Consider tree T1 above

    Show the contents of a three-array implementation of the tree.



  3. Consider k-ary tree T2:

                      root: a
             children of a: b c  d
             children of b: e
             children of c: f g
             children of d: h i j k
             children of h: l m n  
            

    Convert the k-ary tree to a binary tree T3. Then answer the following questions about T3.

    What is the height of T3?

  4. In T3, what is the depth of node k? Should be a non-negative int. Do not start with a space.

  5. In T3, what is the height of node f? Should be a non-negative int. Do not start with a space.

  6. How many leaves does T3 have?

  7. How many interior nodes does T3 have?

  8. How many T3 nodes have exactly one child? Should be a non-negative int. Do not start with a space.

  9. In what sequence are T3 nodes visited in a preorder traversal of the tree?

  10. In what sequence are T3 nodes visited in an inorder traversal of the tree? Do not start with a space. Put exactly one space between to letters. All letters should be lowercase.

  11. In what sequence are T3 nodes visited in a postorder traversal of the tree?

  12. Which nodes are the proper ancestors of T3 node n?
  13. Which nodes are the descendants of T3 node f?