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
- 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.
- 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.
- 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.
- 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