You are on page 1of 63

Chapter 11: Trees and Networks

Discrete Mathematical Structures:


Theory and Applications
Learning Objectives

 Learn the basic properties of trees

 Explore applications of trees

 Learn about networks

Discrete Mathematical Structures: Theory and Applications 2


Trees

 Each atom of a chemical


compound is represented
by a point in a plane

 Atomic bonds are


represented by lines

 Shown in Figure 11.1 for


the chemical compound
with the formula C4H10.

Discrete Mathematical Structures: Theory and Applications 3


Trees

 In chemistry, chemical
compounds with formula
CkH2k+2 are known as paraffins,
which contain k carbon atoms
and 2k + 2 hydrogen atoms.

 In the graphical representation, each of the carbon atoms


corresponds to a vertex of degree 4 and each of the hydrogen
atoms corresponds to a vertex of degree 1.
 For the same chemical formula C4H10, the graph shown in Figure
11.2 is also a representation.

Discrete Mathematical Structures: Theory and Applications 4


Trees

 These graphs are connected and have no cycles. Hence, each of


these graphs is a tree.
Discrete Mathematical Structures: Theory and Applications 5
Trees

 Consider the graphs shown in Figure 11.4. Each of these


graphs is connected.
 However, each of these graphs has a cycle. Hence, none of
these graphs is a tree.

Discrete Mathematical Structures: Theory and Applications 6


Trees

Discrete Mathematical Structures: Theory and Applications 7


Trees

 Consider the graph shown in Figure 11.5. This is a


connected graph and it has at least two vertices of
degree 1. But it contains a cycle.
 Hence, it is not a tree.
Discrete Mathematical Structures: Theory and Applications 8
Trees

Discrete Mathematical Structures: Theory and Applications 9


Trees

Discrete Mathematical Structures: Theory and Applications 10


Discrete Mathematical Structures: Theory and Applications 11
Trees

Discrete Mathematical Structures: Theory and Applications 12


Rooted Tree

Discrete Mathematical Structures: Theory and Applications 13


Rooted Tree
 The level of a vertex v is the length of the path from the root to v.

Discrete Mathematical Structures: Theory and Applications 14


Discrete Mathematical Structures: Theory and Applications 15
Discrete Mathematical Structures: Theory and Applications 16
Discrete Mathematical Structures: Theory and Applications 17
 The root of this binary tree is A. Vertex B is the left child of A and
vertex C is the right child of A. From the diagram, it follows that
B is the root of the left subtree of A, i.e., the left subtree of the
root. Similarly, C is the root of the right subtree of A, i.e., the
right subtree of the root. LA = {B, D, E, G} and RA = {C, F ,H}.
Moreover, for vertex F , the left child is H and F has no right
child.

Discrete Mathematical Structures: Theory and Applications 18


Rooted Tree

Discrete Mathematical Structures: Theory and Applications 19


Rooted Tree

Discrete Mathematical Structures: Theory and Applications 20


Rooted Tree
 Binary Tree Traversal
 Item insertion, deletion, and lookup operations require
the binary tree to be traversed. Thus, the most common
operation performed on a binary tree is to traverse the
binary tree, or visit each vertex of the binary tree. The
traversal must start at the root because one is typically
given a reference to the root. For each vertex, there are
two choices.
 Visit the vertex first.
 Visit the subtrees first.

Discrete Mathematical Structures: Theory and Applications 21


Rooted Tree
 Inorder Traversal: In an inorder traversal, the
binary tree is traversed as follows.

1. Traverse the left subtree.

2. Visit the vertex.

3. Traverse the right subtree.

Discrete Mathematical Structures: Theory and Applications 22


Rooted Tree
 Preorder Traversal: In a preorder traversal, the
binary tree is traversed as follows.

1. Visit the vertex.

2. Traverse the left subtree.

3. Traverse the right subtree.

Discrete Mathematical Structures: Theory and Applications 23


Rooted Tree
 Postorder Traversal: In a postorder traversal, the
binary tree is traversed as follows.

1. Traverse the left subtree.

2. Traverse the right subtree.

3. Visit the vertex.

Discrete Mathematical Structures: Theory and Applications 24


Rooted Tree
 Each of these traversal algorithms is recursive.
 The listing of the vertices produced by the inorder
traversal of a binary tree is called the inorder
sequence.
 The listing of the vertices produced by the preorder
traversal of a binary tree is called the preorder
sequence.
 The listing of the vertices produced by the postorder
traversal of a binary tree is called the postorder
sequence.

Discrete Mathematical Structures: Theory and Applications 25


Discrete Mathematical Structures: Theory and Applications 26
Rooted Tree
 Binary Search Trees
 To determine whether 50 is in the
binary tree, any of the previous
traversal algorithms to visit each
vertex and compare the search item
with the data stored in the vertex
can be used.
 However, this could require
traversal of a large part of the
binary tree, so the search would be
slow.
 Each vertex in the binary tree must
be visited until either the item is
found or the entire binary tree has
been traversed because no criteria
exist to guide the search.

Discrete Mathematical Structures: Theory and Applications 27


Rooted Tree
 Binary Search Trees
 In the binary tree in Figure
11.22, the value of each
vertex is larger than the
values of the vertices in its
left subtree and smaller
than the values of the
vertices in its right subtree.
 The binary tree in Figure
11.22 is a special type of
binary tree, called a binary
search tree.

Discrete Mathematical Structures: Theory and Applications 28


Discrete Mathematical Structures: Theory and Applications 29
Discrete Mathematical Structures: Theory and Applications 30
Rooted Tree

Discrete Mathematical Structures: Theory and Applications 31


Rooted Tree
 The usual notation for writing arithmetic expressions
is called infix notation, in which the operator is
written between the operands.
 For example, in the expression a + b, the operator + is
between the operands a and b. In infix notation, the
operators have precedence. That is, expressions are
evaluated from left to right, and multiplication and
division have higher precedence than addition and
subtraction.

Discrete Mathematical Structures: Theory and Applications 32


Rooted Tree

 If operators were written before the operands


(prefix, or Polish notation; for example, +xy) or
after the operands (suffix, postfix, or reverse
Polish notation; for example, xy+), the
parentheses could be omitted.

 For example, the expression x + y * z in a postfix


expression is xyz * +

Discrete Mathematical Structures: Theory and Applications 33


Rooted Tree

Discrete Mathematical Structures: Theory and Applications 34


Spanning Trees

Discrete Mathematical Structures: Theory and Applications 35


Spanning Trees

Discrete Mathematical Structures: Theory and Applications 36


Discrete Mathematical Structures: Theory and Applications 37
Discrete Mathematical Structures: Theory and Applications 38
Discrete Mathematical Structures: Theory and Applications 39
Spanning Trees
 Consider the graph in Figure
11.38, which represents a
company’s airline connections
among seven cities. The
number on each edge
represents some cost factor of
maintaining the connection
between the cities.

 A weighted tree is a tree such that each edge in the tree is assigned a
nonnegative real number, called the weight of the edge.

Discrete Mathematical Structures: Theory and Applications 40


Discrete Mathematical Structures: Theory and Applications 41
Discrete Mathematical Structures: Theory and Applications 42
Discrete Mathematical Structures: Theory and Applications 43
Discrete Mathematical Structures: Theory and Applications 44
Networks

Discrete Mathematical Structures: Theory and Applications 45


Discrete Mathematical Structures: Theory and Applications 46
Discrete Mathematical Structures: Theory and Applications 47
Networks

Discrete Mathematical Structures: Theory and Applications 48


Networks

Discrete Mathematical Structures: Theory and Applications 49


Discrete Mathematical Structures: Theory and Applications 50
Discrete Mathematical Structures: Theory and Applications 51
Discrete Mathematical Structures: Theory and Applications 52
Discrete Mathematical Structures: Theory and Applications 53
Discrete Mathematical Structures: Theory and Applications 54
Discrete Mathematical Structures: Theory and Applications 55
Discrete Mathematical Structures: Theory and Applications 56
Discrete Mathematical Structures: Theory and Applications 57
Discrete Mathematical Structures: Theory and Applications 58
Discrete Mathematical Structures: Theory and Applications 59
Discrete Mathematical Structures: Theory and Applications 60
 Consider the bipartite graph G = (V , E) of Figure 11.74,
where V = {v1, v2, v3, v4, v5, v6, v7} and E = {e1, e2, e3, e4, e5,
e6, e7, e8}. Here V1 = {v1, v2, v3} and V2 = {v4, v5, v6, v7}.

Discrete Mathematical Structures: Theory and Applications 61


Networks

 The s-t network NG associated with G is shown in Figure


11.75. Each arc in NG is assigned a capacity 1. Hence,
NG is a transport network.

Discrete Mathematical Structures: Theory and Applications 62


Discrete Mathematical Structures: Theory and Applications 63

You might also like