Mathematical Foundations of Computer Science Lecture Outline
Mathematical Foundations of Computer Science Lecture Outline
Lecture Outline
October 23, 2018
Spanning Trees
A spanning subgraph of a graph G is a subgraph with vertex set V (G). A spanning tree is
a spanning subgraph that is a tree.
Rooted Trees
A rooted tree is a tree in which one vertex is distinguished from the others and is called the
root. The level of a vertex, say u, is the number of edges along the unique path between u
and the root. The height of a rooted tree is the maximum level of any vertex in the tree.
Given any vertex of a rooted tree, the children of v are neighbors of v that are one level
away from the root than v. If a vertex v is a child of u, then u is called the parent of v. Two
vertices that are both children of the same parent are called siblings. Given vertices v and
w, if v lies on the unique path between w and the root, then v is an ancestor of w and w is
a descendant of v. A vertex in a rooted tree is called a leaf if it has no children. Vertices
that have children are called internal vertices. The root is an internal vertex unless it is
the only vertex in the graph, in which case it is a leaf. These definitions are illustrated
in Figure 1. A binary tree is a rooted tree in which every internal vertex has at most two
children. Each child in the binary tree is designated either a left child or a right child (but
not both). A full binary tree is a binary tree in which each internal vertex has exactly two
children.
Given an internal vertex v of a binary tree T , the left subtree of v is the binary tree
whose root is the left child of v, whose vertices consists of the left child of v and all its
descendants, and whose edges consist of all those edges of T that connect the vertices of
the left subtree together. The right subtree of v is defined analogously.
2 Lecture Outline October 23, 2018
root
level 0
u
level 1
v w level 2
level 3
level 4
Example. Prove the following. If k is a positive integer and T is a full binary tree with
k internal vertices then T has a total of 2k + 1 vertices and has k + 1 leaves.
Solution. Suppose T is a full binary tree with k internal vertices. Observe that the set
of all vertices of T can be partitioned into two disjoint subsets: the set of all vertices in T
that have a parent and the set of vertcies in T that do not have a parent. The root of T is
the only vertex in T that does not have a parent. Also, every internal vertex of a full binary
tree has exactly two children. Thus, the total number of children of all internal vertices
equals 2k. This is also the number of vertices that have a parent. Adding one for the root
to this number gives us the total number of vertices in T to be 2k + 1.
Also, the total number of vertices in T is the sum of the number of internal vertices in T
and the number of leaves in T . Hence, the number of leaves in T equals 2k + 1 − k = k + 1.
Solution. We will prove the claim by doing induction on h. Let P (h) be the property
that a binary tree of height at most h has at most 2h leaves.
number of leaves in T is at most 2 × 2k = 2k+1 . This proves that P (k + 1) is true and hence
completes the proof.
Hamiltonian Graphs
A Hamiltonian cycle in a graph G is a cycle in which each vertex of G appears exactly
once. A graph is Hamiltonian if it contains a Hamiltonian cycle.
Example. For any integer n ≥ 3, let G be a simple graph on n vertices, and assume that
all vertices in G are of degree at least n/2. Prove that G has a Hamiltonian cycle.
Solution. Assume for contradiction that G does not have a Hamiltonian cycle. Add new
edges to G one-by-one, until we come to a point where adding an edge, say (x, y), creates a
Hamiltonian cycle. Let G0 be the graph in which all vertices have degree at least n/2 and
G0 does not have a Hamiltonian cycle, but adding (x, y) will make G0 Hamiltonian. Since
adding edge (x, y) creates a Hamiltonian cycle in G0 , it must be that G0 has a Hamiltonian
path that begins at x and ends at y. Let the path be x = v1 , v2 , . . . , vn−1 , vn = y. We
now apply the pigeon-hole principle as follows. Let the pigeons be the edges incident on
the vertices x and y, and let the holes be the (n − 1) edges of the form (vi , vi+1 ), where
1 ≤ i ≤ n−1. An edge (pigeon) of the form (x, vi ) is assigned to the “hole” (vi−1 , vi ) and an
edge (pigeon) of the form (y, vi ) is assigned to the “hole” (vi , vi+1 ). Since deg(x) ≥ n/2 and
deg(y) ≥ n/2 and at most one edge incident on x (or y) is assigned to a hole, by the pigeon-
hole principle, there must be i such that 3 ≤ i ≤ n − 1 and there is an edge (x, vi ) and an
edge (y, vi−1 ) (see figure below). Note that since the edge (x, y) does not exist in G0 , the hole
corresponding to (v1 , v2 ) only has one edge, namely (x, v2 ). Similarly, the hole (vn−1 , vn )
will only contain the edge (y, vn−1 ). But this would mean that xv2 v3 · · · vi−1 yvn−1 vn−2 · · · vi
is a Hamiltonian cycle, a contradiction.
v2 vi−1 vi vn−1
x y