Trees
Introduction
A graph is a tree if and only if there is a unique simple path between any two vertices of .
Every tree, with , has at least two vertices that have degree 1.
Every tree with vertices has exactly edges.
Rooted trees
A rooted tree, is a pair where is a tree, and is a chosen root vertex of the tree. Often, the edges of a rooted tree are viewed as being directed, such that for every vertex the unique path from to is directed away from (or towards) .
-
For each node , the parent of that node is the unique vertex such that . is then called a child of . Two vertices with the same parent are called siblings.
-
A leaf is a vertex with no children. Non-leaves are called internal vertices.
-
The height of a rooted tree is the length of the longest directed path from the root to any leaf.
-
The ancestors (or descendants) of a vertex are all vertices such that there is a directed path from to (from to , respectively).
-
The subtree rooted at , is the subgraph containing and all its descendants.
m-ary trees
For , A rooted tree is called a m-ary tree if every internal node has at most children. It is called a ‘full’ m-ary tree if every internal node has exactly children. An m-ary tree with is called a binary tree.
A rooted ordered tree is a rooted tree where the children of each internal vertex are linearly ordered according to some ordering. This is normally drawn with the lower ordered child on the left and the higher ordered child on the right.
For all , every full m-ary tree with internal vertices has exactly vertices. Every vertex other than the root is a child of an internal vertex. There are thus such children, plus 1 root.
For all , a full m-ary tree with:
-
vertices has internal vertices and leaves.
-
internal vertices has vertices and leaves.
-
if , then if the m-ary tree has leaves then it has vertices and internal vertices.
There are at most leaves in an m-ary tree of height .
If an m-ary tree has leaves, then its height .
Spanning trees
For a simple undirected graph , a spanning tree of is a subgraph of such that is a tree and contains every vertex of .
Every connected graph has a spanning tree.
Prim’s algorithm
Input: Connected, edge-weighted, undirected graph.
Output: A minimum-cost spanning tree for .
Initialize: T = {e} (where e is a minimum-weight edge in E)
for i = 1 to n − 2 do
Let e' = a minimum-weight edge incident to
some vertex in T, and not forming a circuit
if added toT;
T = T ∪ {e'};
end for
Output the tree T