page last updated 3/29/08
Countries
States
Counties
Townships
Colleges
Departments
Courses
Sections
Students
Sentence
Noun-Phrase Verb-Phrase
Verb-Phrase
Verb Noun-Phrase
etc.
Directory structures
Type hierarchy as example


| Node |
|
| Root | top element of the hierarchical structure; the starting element. There is only one root per tree |
| Child |
|
| Parent |
|
| Leaf | a node that has no children |
| Descendant |
|
| Ancestor |
|
| Sibling | child node that has the same parent as another node |
| Edge/branch | the line or connection between a parent and child (there may be a weight value associated with the edge) |
| Path | the sequence of edges between a node and one of its descendents |
| Path length | the number of edges in a path |
| Interior node | a node that has at least one child |
| Depth or level | the length of the path connecting a node to the root. The root's depth or level is 0 |
| Height | the longest path length in the tree |
| Subtree | the tree made of all descendents using some non-root node |



Nonrecursive definition of a general tree: A general tree is either empty or consists of a finite set of nodes and a finite set of edges that connect pairs of nodes. The node at one end of an edge is called the parent and at the other the child. One node is distinguished from all others and is called the root. All nodes except the root are connected by an edge to exactly one parent.
Recursive definition of a general tree: A general tree is either empty or consists of a finite set of nodes T. One node r is distinguished from all others and is called the root. In addition, the set T-{r} is partitioned into disjoint subsets, each of which is a general tree.
Recursive definition of a binary tree: A binary tree is either empty or consists of a root plus a left subtree and a right subtree, each of which are binary trees.
Each node consists of a value field and links to each of its children.
In the
case of a general tree, the node must be contain enough links for the maximum
number of children. This approach has an artificial limit that you may
want to avoid. Consider the general tree to the right and draw its linked
representation. What degree of links (maximum number of children) are
needed?
Binary
trees have only a pair of links: left child and right child.
Consider the binary tree to the right and draw its representation.
A binary tree can be used to represent any general tree. The left child holds the first child of the original general tree and the right child holds the next sibling. Represent the above general tree in this binary tree definition.
When
a tree is complete, an array can efficiently represent a binary tree.
A complete binary tree is one that each level except the last has a complete
complement of nodes and if the nodes on the last level are filled in from the
left.
The array order would be: A B C E G K M Q W
A full binary tree is one where all the leaves are on the same level, and every non-leaf node has two children.
Note: In the MA 116 textbook, the definition of a full binary tree is simply "every non-leaf node has two children."
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| A | B | C | E | G | K | M | Q | W |
Given an arbitrary position p, you can calculate its parent, left child and right child, left and right siblings:
parent = (p-1)/2
leftSibling = i-1
rightSibling = i+1
leftChild = i*2+1
rightChild = i*2+2
This is used for the heap data structures.
A BST is a specialized binary tree with the following properties

Traversal Definitions
Preorder traversal: Visit the root, visit the left subtree, visit the right subtree
Inorder traversal: Visit the left subtree, visit the root, visit the right subtree
Postorder traversal: Visit the left subtree, visit the right subtree, visit the root


Consist of exactly one abstract method:
public int compareTo (Object o); // Returns a negative integer, zero, or a positive integer as this object //is less than, equal to, or greater than the parameter object
Consistent with the way we have been using compareTo (in Listable)
Our trees will hold objects of type Comparable
The BSTInterface.java interface (code only)

The BSTNode class (code)
The BinarySearchTree class (code)