Trees

Introduction

A graph GG is a tree if and only if there is a unique simple path between any two vertices of GG.

Every tree, T=(V,E)T = (V,E) with V2|V| \ge 2, has at least two vertices that have degree 1.

Every tree with nn vertices has exactly n1n-1 edges.

Rooted trees

A rooted tree, is a pair (T,r)(T,r) where T=(V,E)T = (V,E) is a tree, and rVr \in V is a chosen root vertex of the tree. Often, the edges of a rooted tree (T,r)(T,r) are viewed as being directed, such that for every vertex vv the unique path from rr to vv is directed away from (or towards) rr.

  • For each node v,=/,,rv \\, {=}\mathllap{/\\,} \\, r, the parent of that node is the unique vertex uu such that (u,v)E(u,v) \in E. vv is then called a child of uu. 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 vv are all vertices u,=/,,vu \\, {=}\mathllap{/\\,} \\, v such that there is a directed path from uu to vv (from vv to uu, respectively).

  • The subtree rooted at vv, is the subgraph containing vv and all its descendants.

m-ary trees

For m1m \ge 1, A rooted tree is called a m-ary tree if every internal node has at most mm children. It is called a ‘full’ m-ary tree if every internal node has exactly mm children. An m-ary tree with m=2m = 2 is called a binary tree.

A rooted ordered tree is a rooted tree (T,r)(T,r) where the children of each internal vertex vv 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 m1m \ge 1, every full m-ary tree with ii internal vertices has exactly m(i+1)m(i + 1) vertices. Every vertex other than the root is a child of an internal vertex. There are thus m×im \times i such children, plus 1 root.

For all m1m \ge 1, a full m-ary tree with:

  • nn vertices has (n1)/m(n−1)/m internal vertices and ((m1)n+1)/m((m−1)n+1)/m leaves.

  • ii internal vertices has m(i+1)m(i + 1) vertices and (m1)i+1(m−1)i + 1 leaves.

  • if m2m \ge 2, then if the m-ary tree has ll leaves then it has (ml1)/(m1)(ml−1)/(m−1) vertices and (l1)/(m1)(l−1)/(m−1) internal vertices.

There are at most mhm^h leaves in an m-ary tree of height hh.

If an m-ary tree has ll leaves, then its height hlogmlh \ge \lceil{\log_ml}\rceil.

Spanning trees

For a simple undirected graph GG, a spanning tree of GG is a subgraph TT of GG such that TT is a tree and TT contains every vertex of GG.

Every connected graph GG has a spanning tree.

Prim’s algorithm

Input: Connected, edge-weighted, undirected graph.

Output: A minimum-cost spanning tree TT for GG.

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