Lab - Euler Tours of General Trees

Preface

This lab is quite different from others. You will not be writing any lines of code, and you will not be turning in any printouts. Instead, you will be required to solve a few puzzles and to demonstrate your success in person with one of the course TAs. (Don't worry - you will be writing plenty of code other weeks!)

Overview

The textbook discusses performing an Euler Tour on a tree as a unified, recursive framework for a variety of common tree traversals. Our goal in this lab is to make sure you get a very well grounded understanding of this general concept, and the various things you might accomplish by customizing the process.

Actually, to be specific, the book only discusses the concept of an Eulur Tour in the context of binary trees. The three common traversal orders are generaly known as "preorder," "inorder," and "postorder", depending on when you consider "visiting" a node, relative to its children. In this context, the Eulur tour can be implemented as:

EulerTour (Tree T, Position p) {

  // consider this the time when p is visited  "on the left"

  if (T.isInternal(p))
    EulerTour(T, T.leftChild(p));

  // consider this the time when p is visited  "from below"

  if (T.isInternal(p))
    EulerTour(T, T.rightChild(p));

  // consider this the time when p is visited  "on the right"
}

The same concept can be applied to general trees as well (though the concept of "inorder" is not quite well defined). In this context, the pseudocode might appear as:

EulerTour (Tree T, Position p) {

  // consider this the time when p is visited  "on the left"

  Iterator children = T.children(p);
  while (children.hasNext()) {
     Position child = (Position) children.nextObject();
     EulerTour(T, child);

     // if there are still more children to come,
     // consider this a time when p is visited  "from below"
  }

  // consider this the time when p is visited  "on the right"
}

The Applet

Your Task

Please answer the following questions and turn in your answers to the TA.

  1. Load the tree "binary.txt" and begin an Euler tour with pauses turned on for visits "on the right."
    What node is the tour at when the first pause occurs?
    When the second pause occurs?
    When the third pause occurs?



  2. Using "binary.txt" turn off all pauses and turn on the print option "from bottom." Run the entire Euler tour and report the output generated by this tour.


  3. When running an Euler Tour on the "disk.txt" tree, what are the respective second to last and last two nodes to be visited "on the left"?

    "from the bottom"?

    "on the right"?

    Note: To get these, you can either use pauses (time consuming), look at the last two pieces of output (easier), or answer the question on your own without using the software (are you right?).


  4. If using the "simple.txt" tree, what print button(s) would you need to turn on to get output which is in alphabetical order?


  5. If using the "simple.txt" tree, what output do you get if all three print buttons are turned on.


  6. If using the "paper.txt" tree, what print button(s) would you need to turn on to get output which is essentially a Table of Contents?


  7. Returning to "simple.txt" what combination of print buttons should be turned on in order to get the output:
    MDAAGFFKKGDTPPWWTM.


I could probably try to do more questions, but this seems enough. If you have extra time, keep playing with the software. Pick some new settings for the switches and see if you can predict the behavior of the algorithm ahead of time on paper. Then run the Applet and see if you were right.


Acknowledgment

We are grateful to Min Wang, a former Loyola student, for developing the original version of this software as an independent project in 2000.


Last modified: 26 September 2002