Trees
Trees
MAT230
Discrete Mathematics
Fall 2019
1 What is a Tree?
2 Spanning Trees
3 Rooted Trees
4 Binary Trees
Some examples:
Definition
A forest is an undirected graph whose components are all trees.
Theorem
Let T = (V , E ) be an undirected graph with no self-loops and |V | = n.
Then the following statements are equivalent:
1 T is a tree.
2 Any two vertices of T are connected by exactly one path.
3 T is connected and every edge is an isthmus (its removal disconnects
T ).
4 T contains no cycles, but the addition of any new edge creates
exactly one cycle.
5 T is connected and has n − 1 edges.
Definition
Let G = (V , E ) be a connected undirected graph. A spanning set for G
is a subset E 0 of E such that (V , E 0 ) is connected.
Definition
Let G be a connected undirected graph. The subgraph T is a spanning
tree for G if T is a tree and every node in G is a node in T .
Definition
If G is a weighted graph, then T is a minimal spanning tree of G if it is
a spanning tree and no other spanning tree of G has smaller total weight.
Definition
Every nonempty tree can have a particular vertex called a root. In a
rooted tree, the root is at level 0. The level of all other vertices is one
greater than the number of edges in the walk from the root to the vertex.
The height of a tree is the number of levels in the tree.
Definition
A vertex u in a rooted tree is a parent of a vertex v if v is adjacent to u
and the level of v is one greater than the level of u. In this case v is a
child of u. Two or more vertices are siblings if they have the same parent.
Definition
Nonroot vertices of degree 1 in a tree are called the leaves of the tree. All
other vertices are called internal vertices.
E B F D A
A J B C D
G C K E F G H I J
H I K
u
u
v
v
In this case, we can choose either r
or s to be the root of the merged
tree.
MAT230 (Discrete Math) Trees Fall 2019 13 / 19
Kruskal’s Algorithm (Version 2)
Definition
A binary tree T is a tree that has zero or more nodes in which each node
has at most two children. Each nonleaf node has left subtree and a right
subtree, either of which may be empty.
Definition
A binary tree T is a tree that has zero or more nodes in which each node
has at most two children. Each nonleaf node has left subtree and a right
subtree, either of which may be empty.
Definition
A binary tree T is a tree that has zero or more nodes in which each node
has at most two children. Each nonleaf node has left subtree and a right
subtree, either of which may be empty.
Definition
A binary tree T is a tree that has zero or more nodes in which each node
has at most two children. Each nonleaf node has left subtree and a right
subtree, either of which may be empty.
Inorder Traversal:
1 Inorder traverse the left subtree
2 Visit the root of the tree
3 Inorder traverse the right subtree
Postorder Traversal:
1 Postorder traverse the left subtree
We can diagram them with trees. For example, trees for a + b and c/d are
+ /
a b c d
+ /
3 × + 5
4 − 7 3
5 3
This tree is not unique, other binary trees could be used to represent the
same expression.
+ /
3 × + 5
4 − 7 3
5 3
+ /
3 × + 5
4 − 7 3
5 3
Preorder traversal: + + 3 × 4 − 5 3 / + 7 3 5
+ /
3 × + 5
4 − 7 3
5 3
Preorder traversal: + + 3 × 4 − 5 3 / + 7 3 5
Postorder traversal: 3 4 5 3 − × + 7 3 + 5 / +
+ /
3 × + 5
4 − 7 3
5 3
Preorder traversal: + + 3 × 4 − 5 3 / + 7 3 5
Postorder traversal: 3 4 5 3 − × + 7 3 + 5 / +