0% found this document useful (0 votes)
35 views

Discrete Math 6

Uploaded by

plabonrahman.me
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Discrete Math 6

Uploaded by

plabonrahman.me
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 47

Graph and Tree

1
Basic Definitions
A graph G = (V ,E) consists of V , a nonempty set of vertices (or
nodes) and E, a set of edges. Each edge has either one or two
vertices associated with it, called its endpoints. An edge is said to
connect its endpoints.

(i) V consists of vertices A, B, C, D. Therefore V={A, B, C, D}


(ii) E consists of edges e1 = {A,B}, e2 = {B,C}, e3 = {C,D}, e4 =
{A,C}, e5 = {B,D}.
2
A graph in which each edge connects two different vertices and
where no two edges connect the same pair of vertices is called a
simple graph.

graphs that have more than one edge connecting the same pair of
vertices. Graphs that may have multiple edges connecting the same
vertices are called multigraphs.

Graphs that may include loops, and possibly multiple edges


connecting the same pair of vertices or a vertex to itself, are
sometimes called pseudographs.
A directed graph (or digraph) (V ,E) consists of a nonempty set of
vertices V and a set of directed edges (or arcs) E. Each directed
edge is associated with an ordered pair of vertices. The directed
edge associated with the ordered pair (u, v) is said to start at u and
end at v.

When a directed graph has no loops and has no multiple directed


edges, it is called a simple directed graph.

Directed graphs that may have multiple directed edges from a


vertex to a second (possibly the same) vertex are used to model
such networks. We called such graphs directed multigraphs.

4
Consider the directed graph G pictured in Fig. below. It consists of four vertices,
A, B, C, D, that is, V (G) = {A,B,C,D} and the seven following edges:
E(G) = {e1, e2, . . . , e7} = {(A,D), (B, A), (B, A), (D,B), (B,C), (D,C), (B, B)}
The edges e2 and e3 are said to be parallel since they both begin at B and end at A.
The edge e7 is a loop since it begins and ends at B.
6
Precedence Graphs
Computer programs can be executed more rapidly by executing certain statements
concurrently. It is important not to execute a statement that requires results of
statements not yet executed. The dependence of statements on previous statements
can be represented by a directed graph. Each statement is represented by a vertex,
and there is an edge from one statement to a second statement if the second
statement cannot be executed before the first statement. This resulting graph is
called a precedence graph.

Example-1

7
Ex-1

8
Exercises-2
determine whether the graph
shown has directed or
undirected edges, whether it
has multiple edges, and
whether it has one or more
loops. Use your answers to
determine the type of graph in
Table 1 this graph is.

9
The degree of a vertex in an undirected graph is the number of edges
incident with it, except that a loop at a vertex contributes twice to the
degree of that vertex. The degree of the vertex v is denoted by deg(v).

Example-2
What are the degrees of the vertices in the graphs G and H
displayed in Figure 1?
Solution: In G, deg(a) = 2, deg(b) = deg(c) = deg(f ) = 4, deg(d ) =
1, deg(e) = 3, and deg(g) = 0. H, deg(a) = 4, deg(b) = deg(e) = 6,
deg(c) = 1, and deg(d ) = 5.

10
EXAMPLE 3
How many edges are there in a graph with 10 vertices each of
degree six?
Solution: Because the sum of the degrees of the vertices is 6 ・ 10 =
60, it follows that 2m = 60 where m is the number of edges.
Therefore, m = 30.

11
Theorem
An undirected graph has an even number of vertices of odd
degree.

12
In a graph with directed edges the in-degree of a vertex v, denoted
by deg−(v), is the number of edges with v as their terminal vertex.
The out-degree of v, denoted by deg+(v), is the number of edges
with v as their initial vertex. (Note that a loop at a vertex
contributes 1 to both the in-degree and the out-degree of this
vertex.)
EXAMPLE 4 Find the in-degree and out-degree of each vertex in
the graph G with directed edges shown in Figure 2.

Solution: The in-degrees in G are deg−(a) = 2, deg−(b)


= 2, deg−(c) = 3, deg−(d) = 2, deg−(e) = 3,
and deg−(f ) = 0.
The out-degrees are deg+(a) = 4, deg+(b) = 1, deg+(c) =
2,deg+(d) = 2, deg+(e) = 3, and deg+(f ) = 0.

13
Some Special Simple Graphs

Complete Graphs
A complete graph on n vertices, denoted by Kn, is a simple graph
that contains exactly one edge between each pair of distinct vertices.
The graphs Kn, for n = 1, 2, 3, 4, 5, 6, are displayed in Figure below.
A simple graph for which there is at least one pair of distinct vertex
not connected by an edge is called noncomplete.

14
Cycles
A cycle Cn, n ≥ 3, consists of n vertices v1, v2, . . . , vn and edges
{v1, v2}, {v2, v3}, . . . , {vn−1, vn}, and {vn, v1}. The cycles C3, C4,
C5, and C6 are displayed in Figure below.

15
Wheels
We obtain a wheel Wn when we add an additional vertex to a
cycle Cn, for n ≥ 3, and connect this new vertex to each of the n
vertices in Cn, by new edges. The wheels W3, W4, W5, and W6 are
displayed in Figure below.

16
n-Cubes
An n-dimensional hypercube, or n-cube, denoted by Qn, is a graph
that has vertices representing the 2n bit strings of length n. Two
vertices are adjacent if and only if the bit strings that they
represent differ in exactly one bit position. We display Q 1, Q2, and
Q3 in Figure below.

17
Bipartite
A simple graph G is called bipartite if its vertex set V can be
partitioned into two disjoint sets V1 and V2 such that every edge in
the graph connects a vertex in V1 and a vertex in V2 (so that no
edge in G connects either two vertices in V1 or two vertices in
V2). When this condition holds, we call the pair (V1, V2) a
bipartition of the vertex set V of G.

18
Complete Bipartite Graphs
A complete bipartite graph Km,n is a graph that has its vertex set
partitioned into two subsets of m and n vertices, respectively with
an edge between two vertices if and only if one vertex is in the first
subset and the other vertex is in the second subset. The complete
bipartite graphs K2,3, K3,3, K3,5, and K2,6 are displayed in Figure
below.

19
A path or circuit of a graph is simple if it
does not contain the same edge more than
once.

20
Euler Paths and Circuits

The town of Königsberg, Prussia (now called Kaliningrad and part


of the Russian republic), was divided into four sections by the
branches of the Pregel River.

The townspeople took long walks through town on Sundays. They wondered whether it
was possible to start at some location in the town, travel across all the bridges once
without crossing any bridge twice, and return to the starting point. The 21 Swiss
mathematician Leonhard Euler solved this problem.
Euler studied this problem using the multigraph obtained when the
four regions are represented by vertices and the bridges by edges.
This multigraph is shown in Figure below.

The question becomes: Is there a simple circuit in this multigraph


that contains every edge? 22
An Euler circuit in a graph G is a simple circuit containing every edge
of G. An Euler path in G is a simple path containing every edge of G.

Theorem
A connected multigraph with at least two vertices has an Euler
circuit if and only if each of its vertices has even degree.

Theorem
A connected multigraph has an Euler path but not an Euler
circuit if and only if it has exactly two vertices of odd degree.

23
EXAMPLE 4
Which graphs shown in Figure below have an Euler path?
Solution:G1 contains exactly two vertices of odd degree, namely, b and d. Hence,
it has an Euler path that must have b and d as its endpoints. One such Euler path
is d, a, b, c, d, b. Similarly,G2 has exactly two vertices of odd degree, namely, b
and d. So it has an Euler path that must have b and d as endpoints. One such
Euler path is b, a, g, f, e, d, c, g, b, c, f, d. G3 has no Euler path because it has six
vertices of odd degree.

24
Hamilton Paths and Circuits
A simple path in a graph G that passes through every vertex
exactly once is called a Hamilton path, and a simple circuit in a
graph G that passes through every vertex exactly once is called a
Hamilton circuit.

DIRAC’S THEOREM
If G is a simple graph with n vertices with n ≥ 3 such that the
degree of every vertex in G is at least n/2, then G has a Hamilton
circuit.

25
TREE
A tree is a connected undirected graph
with no simple circuits.

A rooted tree is a tree in which one vertex has been designated


as the root and every edge is directed away from the root.

26
EXAMPLE 1
Which of the graphs shown in Figure below are trees?
Solution: G1 and G2 are trees, because both are connected graphs
with no simple circuits. G3 is not a tree because e, b, a, d, e is a
simple circuit in this graph. Finally, G4 is not a tree because it is
not connected.

27
A rooted tree is called an m-ary tree if every internal vertex has
no more than m children. The tree is called a full m-ary tree if
every internal vertex has exactly m children. An m-ary tree with m
= 2 is called a binary tree.

EXAMPLE 2
Are the rooted trees in Figure below full m-ary trees for some
positive integer m?

Solution: T1 is a full binary tree because each of its internal vertices has two children. T2 is a full 3-ary
tree because each of its internal vertices has three children. In T3 each internal vertex has five children,
so T3 is a full 5-ary tree. T4 is not a full m-ary tree for any m because some of its internal vertices have
two children and others have three children. 28
THEOREM
A full m-ary tree with i internal vertices contains n = mi + 1 vertices.

Proof:
Every vertex, except the root, is the child of an internal vertex.
Because each of the i internal vertices has m children, there are mi
vertices in the tree other than the root. Therefore, the tree contains n
= mi + 1 vertices.

29
THEOREM

30
Example-3 a) Which vertex is the root?
b) Which vertices are internal?
c) Which vertices are leaves?
d) Which vertices are children of j?
e) Which vertex is the parent of h?
f ) Which vertices are siblings of o?
g) Which vertices are ancestors of m?
h) Which vertices are descendants of b?

3. a) a
b) a, b, c, d, f , h, j , q, t
c) e, g, i, k,l,m, n, o, p, r, s, u
d) q, r
e) c f) p g) f , b, a h) e, f , l,m, n 31
Example-4
How many edges does a tree with 10,000 vertices have?
Ans. e = v-1 = 9999

Example-5
Suppose 1000 people enter a chess tournament. Use a rooted tree
model of the tournament to determine how many games must be
played to determine a champion, if a player is eliminated after one
loss and games are played until only one entrant has not lost.

Ans. The number of players =1000 = number of leaves of full binary


tree.
The number of games = the number of internal vertices,
i = (l-1)/(m-1) = (1000-1)/(2-1) = 999

32
Example-6
How many vertices does a full 5-ary tree with 100 internal
vertices have?

Ans. Given, m = 5 and i =100.


For full m-ary tree, v = mi + 1 = 5 × 100 + 1 = 501.

Example-7
How many edges does a full binary tree with 1000 internal
vertices have?
Ans. m = 2, i =1000
v = mi + 1= 2001
e = v - 1 = 2000

33
Example-8
How many leaves does a full 3-ary tree with 100 vertices have?
m = 3, v = 100
l ={(m-1)v+1}/m = {(3-1) × 100 + 1}/3 = 201/3 = 67

A complete m-ary tree is a full m-ary tree in which every leaf is at


the same level.

34
Example-9
How many vertices and how many leaves does a complete
m-ary tree of height h have?

Ans. The number of leaves = mh


The number of vertices,
1 + m + m2 + m3 +… … … + mh = 1 × (mh+1-1)/(m-1)

Example-10
How many edges are there in a forest of t trees containing
a total of n vertices?

Ans. n-t

35
A rooted m-ary tree of height h is balanced if all leaves are at
levels h or h − 1.
Example-11
Which of the rooted trees shown in Figure 14 are balanced?

Solution: T1 is balanced, because all its leaves are at levels 3 and 4.


However, T2 is not balanced, because it has leaves at levels 2, 3,
and 4. Finally, T3 is balanced, because all its leaves are at
level 3.
Tree Traversal
Procedures for systematically visiting every vertex of an ordered
rooted tree are called traversal algorithms. We will describe three
of the most commonly used such algorithms, preorder traversal,
inorder traversal, and postorder traversal

Preorder traversal
Let T be an ordered rooted tree with root r. If T consists only of r,
then r is the preorder traversal of T . Otherwise, suppose that T1,
T2, . . . , Tn are the subtrees at r from left to right in T . The
preorder traversal begins by visiting r. It continues by traversing
T1 in preorder, then T2 in preorder, and so on, until Tn is traversed
in preorder.
Inorder traversal
Let T be an ordered rooted tree with root r. If T consists only of r,
then r is the inorder traversal of T . Otherwise, suppose that T1,
T2, . . . , Tn are the subtrees at r from left to right. The inorder
traversal begins by traversing T1 in inorder, then visiting r. It
continues by traversing T2 in inorder, then T3 in inorder, . . . , and
finally Tn in inorder.
Spanning Trees
Let G be a simple graph. A spanning tree of G is a subgraph of G
that is a tree containing every vertex of G.

Example-12
Find a spanning tree of the simple graph G shown in Figure
below.
Ans. Some possible spanning tress are shown below
Example-13
Find a spanning tree for each of these graphs.
a) K5 b) K4,4 c) K1,6 d) Q3 e) C5 f ) W5

43
A minimum spanning tree in a connected weighted graph is a
spanning tree that has the smallest possible sum of weights of its
edges.

Prim’s Algorithm of minimum spanning tree


procedure Prim(G: weighted connected undirected graph with n vertices)

T := a minimum-weight edge
for i := 1 to n − 2
e := an edge of minimum weight incident to a vertex in T and not forming a
simple circuit in T if added to T
T := T with e added
return T {T is a minimum spanning tree of G}
Example-14
Use Prim’s algorithm to find a minimum spanning tree in the graph
shown in Figure 3.
Kruskal’s Algorithm of minimum spanning tree
procedure Kruskal(G: weighted connected undirected graph with n vertices)

T := empty graph
for i := 1 to n − 1
e := any edge in G with smallest weight that does not form a simple circuit
when added to T
T := T with e added
return T {T is a minimum spanning tree of G}

46
Example-15
Use Kruskal’s algorithm to find a minimum spanning tree in the
weighted graph.

You might also like