Graph Theory Lecture Notes 4

Application (Minimum Spanning Tree):

Suppose that the vertices of a graph represent towns and the edges of the graph are roads between these towns. Label each edge with the distance between the towns. If it is desired to run optical cable along the roads so that all the towns are connected, where should the cable be put to minimize the amount of cable used? To answer this type of question we need to be able to find a spanning tree in the graph so that the sum of the numbers on the edges is as small as possible (amongst all spanning trees).

Trees

Prop 3.1.4: Every tree with at least one edge has at least two vertices of degree 1 (pendant vertices or leafs).

Prop 3.1.6: Every tree on n vertices contains exactly n-1 edges.

Notation: The number of components of a graph G is denoted by c(G).

Prop 3.1.9: If G is a simple graph with n vertices and k components, then |E| ½(n-k)(n-k+1).

Cor 3.1.10: A simple n-vertex graph with more than ½(n-1)(n-2) edges must be connected.

Theorem 3.1.11: Let T be a graph with n vertices. Then the following statements are equivalent.

  1. T is a tree.
  2. T contains no cycles and has n-1 edges.
  3. T is connected and has n-1 edges.
  4. T is connected and every edge is a cut-edge.
  5. Any two vertices of T are connected by exactly one edge.
  6. T contains no cycles, and for any new edge e, the graph T+e has exactly one cycle.

Rooted Trees

A directed tree is a digraph whose underlying graph is a tree.

Def: rooted tree.

Theorem 3.2.1: A directed tree is representable as a rooted tree if and only if one vertex has indegree 0 and all other vertices have indegree 1.

Def: level (or depth) of a vertex, height of a tree, parent, child, sibling , descendant, ancestor, leaf, internal vertex.

Def: m-ary tree, complete m-ary tree.

Prop 3.2.2: An m-ary tree has at most mk vertices at level k.

Theorem 3.2.3: Let T be an n-vertex m-ary tree of height h. Then h+1 n (mh+1 - 1)/(m-1).

Def: ordered tree

Binary Trees

A binary tree is an ordered 2-ary tree. Each vertex has no more than two children, each designated as either a left-child or a right-child.

Theorem 3.3.1: The complete binary tree of height h has 2h+1 - 1 vertices.

Def: binary code, prefix code

Let T be a binary tree with leaves s1, s2, ... sm such that each leaf si is assigned a weight wi. The average weighted depth of the binary tree T, denoted wt(T) is given by

Huffman Algorithm

Input: A set of symbols S = {s1,s2,...sm} and a set of corresponding weights wi, where wi is the weight associated to the symbol si.

Output: A binary tree representing a prefix code for the set of symbols S whose codewords have minimum average weighted length.

Initialize F to be a forest of isolated vertices, labeled s1,...sm with respective weights w1,..., wm.
For i = 1 to m-1 do

  1. Choose from forest F two trees, T and T', of smallest weights (ties settled by some arbitrary ordering of the trees in F).
  2. Create a new binary tree whose root has T and T' as its left and right subtrees.
  3. Label the edge to T with a 0 and the edge to T' with a 1.
  4. Assign the new tree the weight equal to the sum of the weights of T and T'.
  5. Replace trees T and T' in forest F by the new tree.
Return F.

The binary tree produced by this algorithm is called a Huffman tree,and the corresponding prefix code is called a Huffman code.

Lemma 3.3.3: If the leaves of a binary tree are assigned weights, and if each internal vertex is assigned a weight equal to the sum of its children's weights, then the tree's average weighted depth equals the sum of the weights of its internal vertices.

Theorem 3.3.4: For a given list of weights w1,w2,...,wl, a Huffman tree has the smallest possible average weighted depth among all binary trees whose leaves are assigned those weights.