Tutorial 12: Tree Traversal Algorithms


Introduction

This tutorial consists of a few exercises designed to reinforce your understanding of the tree data structures we have studied so far:


Exercises

  1. Add a method called lookup to the 2-3-4 tree that takes as input an Integer object and return true if the input is in the tree, false otherwise.

  2. In-order traversal of a binary tree: perform a task on the left subtree, then perform the task on the root, and finally perform the task on the right subtree.  Write a binary tree visitor to print the data in a binary tree in in-order traversal.  Add a main method to test your code using BSTInserter and VerticalPrinter.

  3. Pre-order traversal of a binary tree: perform a  task on the root, then perform a task on the left subtree, and finally perform the task on the right subtree.  Write a binary tree visitor to print the data in a binary tree in pre-order traversal.  Add a main method to test your code using BSTInserter and VerticalPrinter.

  4. Post-order traversal of a binary tree: perform a task on the left subtree, then perform the task on the right subtree, and finally perform a  task on the root.  Write a binary tree visitor to print the data in a binary tree in post-order traversal.  Add a main method to test your code using BSTInserter and VerticalPrinter.



D. X. Nguyen, Nov. 21, 1999.
dxnguyen@cs.rice.edu