Trees
Basic tree anatomy
- Family relationships – parents, children, etc..
- Geometric relationships – top, bottom, left, right, etc.
- Biological names – roots, leaves, etc.
Definition: A tree is a connected undirected graph with no simple
circuits
Once a root is specified we can assign directions to each edge. Since there
is a unique path from the root to each node of the graph, we direct each node
away from the root. Thus a tree together with its root produces a graph called a
rooted tree.
- Trees represent organizations
- Trees represent computer file systems
- Used in networks to find best path to send a message over the Internet
- Used to represent chemical formulas.
- Outlines (universal address system).
- Family trees.
Ancestors and parents
- Look up from the node and you will find the ancestors.
- The parent of a node is the one immediately up.
Leaves
Leaves are the nodes that have no children.
Internal Node
- Internal nodes are leaves that have children
- The root is an internal node unless it is the only node in the tree in
which case is a leaf.
Levels
- The nodes of a tree can be arranged into numbered levels.
- The topmost level which contains only the root node is called level 0
In a tree there is exactly one path from the root R to each descendant of
R. More than one path is not a tree. This follows from the definition of tree
given at the beginning.
Truths:
- The level of a node v in a rooted tree is the length of the unique path
from the root to this node.
- The level of the root is defined to be zero.
- The height of a rooted tree is the maximum of the levels of the nodes.
(the longest path from the root to any node)
- A tree with n nodes has n-1 edges
Balanced trees
A rooted m-ary tree of height h is called balanced if all leaves are at
levels h or h-1.
Some problems that can be studied using trees:
- How should items in a list be stored so that an item can be easily
located?
- How should a set of characters can be efficiently coded by bit strings?