Heriot-Watt University
Activities in unit 1 Activities in unit 1 Heriot-Watt University
Heriot-Watt University
Trees (1)
StacksTrees (2)

Trees are useful for data that is stored naturally as a hierarchy, e.g. employees in a corporation. We use an upside-down view of trees compared to the usual countryside version. You'll be using trees all over the course so its fairly important to gain a good understanding of them. We're concentrating on Binary Trees in this topic, i.e. trees where each node has a maximum of two children - the alternative is only touched on briefly in the lecture notes. If you're lost already in the terminology, don't worry, the next part of this topic has a brief reminder of what the terms 'degree', 'child', 'parent', 'root', 'leaf', 'levels' and 'height' all mean in this context.

Here are the method declarations for this structure, for you to refer back to.


public interface BinaryTree{
        public boolean isEmpty();
        public Object root();
        public void makeTree(Object root, Object left, Object right);
        public BinaryTree removeLeftSubtree();
        public BinaryTree removeRightSubtree();
        public void preOrder(Method visit);
        public void postOrder(Method visit);
        public void inOrder(Method visit);
        public void levelOrder(Method visit);
}

Activity Tree Terminology

Activity Tree Traversal Methods

Assessment activity Tree Traversal Quiz

Activity Building Trees from Traversal Pairs

Assessment activity Tree Questions

topStacksTrees (2)

©Heriot-Watt University 2001