You are on page 1of 15

MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

Chapter 4. Graph and Digraphs


Learning outcomes: to learn about
 the concept of graphs and digraphs
 the properties of relations and functions using digraphs
 Eulerian or Hamiltonian paths or circuits and trees.

Defn: Graphs are discrete structures consisting of vertices (nodes/points) and edges
(lines) connecting these vertices. A simple graph G = (V, E) consists of a nonempty set
of vertices, V, and a set E of unordered pairs of distinct elements of V called edges.
a b c
 V(G) = {a, b, c, d, e, f, g, h}
E(G) = {{a, b}, {a, d}, {b, e}, {b, f},
   {c, c}, {c, f}, {d, e}, {e, f},
d e f
{e, g}, {f, g}}
= {ab, ad, be, bf, cc, cf, de, ef, eg, fg}
g h Note: {a, b} = ab = ba

Fig. 1: Graph G Vertex h is called an isolated vertex.


Edge cc is called a loop.

Two graphs G and H are equal iff V(G) = V(H) and E(G) = E(H).

Defn: A directed graph (digraph) D = (V, A) consists of a set of vertices V and a set of
arcs that are ordered pairs of elements of V.
a
 b V = {a, b, c, d, e, f}
A = {(a, b), (b,c), (b, d), (c, a), (c, d), (d, f), (e, c), (f, e)}
c d
Note: (a, b)  (b, a)
 f
e
Fig. 2: Digraph D

Note: A loop is an edge/arc from a vertex to itself. A simple graph has no multiple edges
or loops. In this chapter, we only consider simple graphs.

For a digraph D = (V, A), if (u, v) and (v, u)  A, then both arcs can be represented by an
edge to become a graph G.
a a
D:  G:

b c b c
Fig. 3(a): Digraph Fig. 3(b): Graph obtained from digraph

NOTE: Graph theory terminologies are not standardized!

1
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

4.1 Relations and Digraphs


Let R be a relation on A. The digraph representation of R is as follows:
1) Let all elements in A be vertices.
2) For a, b  A, draw an arc from a to b iff a R b or (a, b)  R.

Eg 1: Given A = {1, 2, 3, 4} and R = {(1,2), (2,3), (3,2), (3,4), (4,2), (4,4)}. Draw the
digraph of R.
1 2
 

 
4 3
Fig. 4: Digraph representing R

Eg 2: Find the relation R represented by the following digraph.

2
R=

1 3

4
Fig. 5. Relation and digraph

Given a digraph representation of a relation R, we can determine the properties of R:-


a) Reflexive – every vertex (node) has a loop.

b) Symmetric – if there is an arc from u to v, there is also an arc from v to u.

c) Antisymmetric – there is at most one arc between any 2 distinct vertices.

d) Transitive – if there is an arc from u to v and from v to w, there must be an arc


from u to w.

2
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

Eg 3: Given R = {(a,a), (b,b), (b,c), (c,b), (c,c)} on X = {a, b, c}. Draw the digraph of R
and determine the properties of R. Is R an equivalent relation or a partial order relation?

Eg 4: Given R a relation on A = {2, 4, 5, 8} with x R y iff x  y. Draw a digraph


representing R. Is R reflexive, symmetric, antisymmetric and transitive? Is R an
equivalent relation or a partial order relation?

Eg 5: Given a relation R on A = {2, 3, 5, 8, 9} such that a R b iff a + 1 ≥ b. Draw a


digraph representing R. Is R an equivalence relation or a partial order relation?

Eg 6: Given a relation R on A = {3, 4, 6, 7, 8} such that a R b iff (a + b)/2 is even.


Determine if R is an equivalence relation by inspecting its digraph.

Exercise 4.1
1. Let R be a relation on A. Find the relation R determined by the following digraphs.
Determined if R is reflexive, symmetric, antisymmetric and transitive. Give a reason
if your answer is no. Is R a partial order relation or an equivalence relation?

a) A = {a,b,c,d} b) A = {a,b,c,d,e}

a d a d

b c b c

3
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

c) A = {a,b,c,d,e} d) A = {a,b,c}

a d
a
e
b c b c

2. R is a relation A. Draw the digraph representing each of the following relations.


Determined if it is reflexive, symmetric, antisymmetric and transitive. Explain if your
answer is no. Is R a partial order or equivalence relation.

a) A = {4, 5, 6, 7}, R = {(4,4), (4,6),(5,4), (5,5), (6,4), (6,5), (7,6), (7,7)};


b) A = {–3, 0, 1, 4}, a R b iff b + 6 > a2.
c) A = {1, 2, 3, 4, 6}, a R b iff a divides b.
d) A = {2, 3, 5, 7, 8, 10}, a R b iff (a + b)/2 is odd.

4.2 Functions and Digraphs


A function f : A  B is a special relation such that every element in A is assigned exactly
one element in B. Hence, the digraph representing f has only one arc from each a  A to
its image b  B.

Eg 1: Suppose f = {(2, 4), (3, 5), (6, 7), (8, 10)} is a function from A = {2, 3, 6, 8} B =
{4, 5, 7, 9, 10}. Draw a digraph representing f.

Eg 2: Determine whether the digraphs representation of relations on A = {a, b, c, d, e}


below represent a function. If yes, draw an arrow diagram.

a) b)
b
a b

G: H: a c e
c

e d
d

Fig. 6: Functions and digraphs

Let f : A  B be a function represented by a digraph D.

4
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

a) If f is 1 – 1, then every vertex of B receives at most one in-coming arc.


b) If f is onto, then every vertex of B receives at least one in-coming arc.
c) If f is 1 – 1 and onto, then every vertex of B receives exactly one in-coming arc.

Eg 3: Determine whether the function f : A  B defined below is 1 – 1 or onto by


inspecting its digraph representation.

a) A = {1, 2, 3, 4}, B = {3, 4, 5, 6}, f = {(1,3), (2, 4), (3, 6), (4, 5)}
b) A = {2, 4, 5, 6}, B = {2, 3, 4, 6, 8}, f = {(2, 2), (4, 4), (5, 6), (6, 3)}
c) A = {3, 5, 2, 7, 9}, B = {2, 1, 4, 6}, f = {(3, 2), (5, 1), (2, 2), (7, 4), (9, 6)}
d) A = B = {2, 4, 5, 7, 9} with f = {(2, 4), (4, 7), (7, 5), (5,2), (9,9)}

4.3 Paths and Connectivity


Path: A path of length n is a sequence u1, e1, u2, e2, u3, e3, …, un, en, un+1 where n  0 with
each ui is a vertex and ei is an edge joining ui and ui+1.

(i). The length of a path is the number of edges in it. If a path has n
(ii). A path is elementary if it has no repeated vertex. vertices and m edges,
(iii). A path is simple if it has no repeated edges. then
- m = n – 1.

NOTE: each elementary path is also a simple path but the converse is not true.

If we think of the vertices in a graph as cities and the edges as roads, a path corresponds
to a trip beginning at a city passing through several cities, and terminating at a city.

Eg 1: Find a simple and an elementary path of (a) length 5 that starts at vertex d and ends
at vertex e; (b) length 6 for the graph G in Fig. 7.

a
G b 
c d e

f
Fig. 7

5
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

Connectedness: A graph is connected if there is a path connecting every two vertices.


Otherwise, it is disconnected.

Eg 2: a) Connected b) Disconnected
1 2 1 2
G1: G2:
3 4 3 4

Fig. 8: Connectedness

Note that a connected graph has only one “piece” of vertices and edges. A disconnected
graph has at least two “pieces” of vertices and edges. Each “piece” is a subgraph called
component.

Subgraph: Let G = (V, E) be a graph. A graph G’ = (V’, E’) is a subgraph of G if


V’  V and E’  E. Moreover, if V’ = V, then G’ is a spanning subgraph
of G.

Eg 3:
a  b a b a b

G: c H1: c H2: c

d e d d e

Fig. 9: Subgraph and spanning subgraph

Eg 4: For the graph G in Example 3, find a connected spanning subgraph having the least
number of edges.

For a graph, the degree of a vertex u, deg(u) = the number of edges incident to u. Each
loop on u contributes 2 to the degree of u. The size of G is the number of vertices in G.
Degree and size shows the density of a network.

Eg 5: For the graph G in Fig. 7 and in Fig. 9 above, determine the degree of each vertex.

6
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

Every vertex in a digraph has an in-degree (id) and an out-degree (od). The in-degree is
the number of arcs going into a vertex and the out-degree is the number of arcs going out
from a vertex.

Eg 6: a) For the given digraph, determine the in-degree and out-degree of each vertex.

1 2

 
4 3

Fig. 10: In-degree and out-degree

b) For the digraphs in Fig. 6, determine the in-degree and out-degree of each vertex.

Cycle (or circuit): A closed path that begins and ends at the same vertex. A cycle is
simple (respectively elementary) if there is no repeated edge (respectively vertex). The
length of a cycle is the number of edges in the cycle. The length of a cycle is at least 3.

NOTE: every simple cycle is also elementary but the converse is not true.

Eg 7: In the graph below, find a simple circuit and an elementary circuit of length 7 that
begins at vertex d.

a  b
h e
 

 
g f
d  c
Fig. 11

Is it possible to travel to each of 20 major cities in the world exactly once by taking direct
flight and come back to the starting city? Assume that direct flight is only available
between 2 adjacent vertices.

7
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

a 

 u
m  t 
b e
 n  s f
l 
k  p r 
q g
j 
i 
c h d
Fig. 12

Defn: A cycle (or path) in a graph G is called a Hamiltonian cycle (or path) of G if it
contains every vertex of G exactly once.

Eg 9: Find a Hamiltonian cycle and path for the graph in Fig. 11 and in Fig. 12.

Eg 10: Consider the graphs in Figure 13. G1 and G2 have Hamiltonian path but not
Hamiltonian circuit. In G3, no Hamiltonian path is possible. (Verify this.)

a A B
G1: b   c G2: 1 2  G3:  
d 3 4
5 6 C D
e
Fig. 13 E

Eg 11: Determine which of the given digraphs has a Hamiltonian cycle. If it does, find
such a cycle. If not, find a Hamiltonian path that exists.

In the city of Konigsberg, there are 7 bridges joining the riverbanks and an island as
shown. Is it possible to cross each of the bridge exactly once and return to the starting
point?

Fig. 14: Konigsberg City

8
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

Defn: A cycle (path) in a graph G is called an Eulerian cycle (path) if it contains each
edge of G exactly once.

Eg 12: Which of the graphs below have an Eulerian circuit? Of those that do not, which
has an Eulerian path?

E
 2  4
D 
B C 1 3 5
 A

Fig. 15 Fig. 16
Note: A graph has Eulerian cycle if we can draw all the edges without lifting a pencil so
that no part of the picture is retraced.

Theorem 4.3.1. A nontrivial connected graph G has an Eulerian cycle if and only if
every vertex of G is of even degree.

Theorem 4.3.2. A connected graph G has an Eulerian path (but not Eulerian circuit) if
and only if G has exactly two odd degree vertices. The path must begin at one of these
odd vertices and ends at the other.

Eg 13: Determine which given graph has an Eulerian circuit. Construct such a circuit
when one exists. Explain why if one doesn’t exist and construct an Eulerian path if it
exists. Explain why if it doesn’t exist..

A B 1 2 U V W
  · · · · ·

  3· ·4 ·5 ·P Q·
C D S· ·R
6· ·7
Fig. 16 Fig. 17 Fig. 18

Eg 14: For all the graphs below, tell whether the graph has an Eulerian circuit, and
Eulerian path but no Eulerian circuit, or neither. Give reason for your choice.
   · ·

    · · · · · ·

 · · · · ·

Fig. 19 Fig. 20 Fig. 21

9
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

Exercise 4.3
1. Base on the graph G given below:
 a

b c d  e

f  g  h

a. find the size of the graph G,


b. find the degree of the node a,
c. give an example of a simple path of length 3, that begins at node b,
d. give an example of an elementary circuit,
e. draw the subgraph G1 = G \ {e}.

2. Consider the graph given below:


A B C D
   

 E F  G

H  I J K

a) Find an Eulerian cycle that begins at vertex C. If there is none, explain why.
b) Find a Hamiltonian path in the graph. If there is none, explain why.
c) Can the path B,C,F,B be considered as a Hamiltonian cycle? Give your reason.

3. Consider the following graph.


a

d

e
c b

a) Find an Eulerian path. If it doesn’t exist, give reason(s).


b) Find a Hamiltonian circuit. If it doesn’t exist, give reason(s).

4. Find a connected spanning subgraph with minimum edges for the graph in Q1 to
Q3.

5. Obtain the Hamiltonian path in the graph below.

10
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

6. Determine whether the graph shown has a Eulerian circuit. Give your reason.
If the graph has a Eulerian circuit, give the circuit.

4.4 Tree

A tree is a connected graph that has no cycle, i.e. there is a unique path between any two
of its vertices.

Eg 1: Which of the graphs shown are trees?

a A B
G1: b  c G2: 1 2  G3:  
d 3 4
5 6 C D
e
Fig. 22 E

Defn: A rooted tree (T, vo) is a tree with a vertex vo such that id(vo) = 0. The parent of a
vertex v is the unique vertex u such that there is a directed edge from u to v. Here, v is
called a child of u. Vertices with the same parents are called siblings. The ancestors of a
vertex are the vertices in the path from the root to this vertex. The descendants of a vertex
are the vertices that this vertex can reach in connected path. A vertex that has no children
(od = 0) is called a leaf. The height of T is the maximum level T has.
v0 (root)
· Level 0
v1 · · v2 ·v3 (parent) Level 1
v
v4 · ·5 · · Level 2
v6 (children) v7
· · v9 Level 3
v8

v10 v11 v12 11


MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

· · · Level 4
(leaves)

Fig. 23. A rooted tree


Defn: The subtree of T with vertex x as its root is the subgraph, (T, x) of the tree T
consisting of x as the root and its descendants.

Eg 2: For tree T above, find a subtree of height 2 rooted at (i) v1 and (ii) v5.

Theorem 4.4.1: Let T be a connected graph with n vertices. The following statements are
equivalent.
a) T is a tree.
b) T has n – 1 edges.
c) T has no circuit.

Defn: A spanning tree T of a connected graph G is a tree that contains all vertices of T.
Spanning trees are not unique.

Eg 3: Find a spanning tree rooted at b for the graph G below.

G: a
b
c d e

f
Fig. 24

Theorem 4.4.2. A graph G has a spanning subtree if and only if it is connected.


Defn: An ordered tree is a tree where the children of each internal vertex are ordered
from left to right.

Binary Tree: Rooted tree where every vertex has at most 2 children (except end-vertices
that have no children). The first child is called the left child and the second is called the
right child. The tree rooted at the left (right) child of a vertex is called the left- (right-)
subtree of this vertex.

12
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

Eg 4: The tree that defines a Huffman Code is a binary tree. Use the given tree, show the
code word for each alphabet shown. Encode the words EASE and CAR, also decode the
string 0101110 and 1100101110.

0  1
 0  1
E  0  1
A  0  1
S  
R C
Fig. 25: A Huffman Code tree

Full Binary Tree: A binary tree where every vertex (except the leaves) has exactly two
children.

Eg 5: Tree that shows your biological parents & ancestors.

Note: Labeled trees used to represent algebraic expressions are full binary trees.

Eg 6: Construct a labeled binary tree for the following expressions.


a) (3^x) – (2 * y)
b) (3 – (2 * x))+ ((y – 2) – (3 + z))
c) (7 + 4y)/(5x – 6)
d) ((7 – a)/5) * ((a+b)^3)
e)


a) 
^  *

   
3 x 2 y

13
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

Decision Tree: A rooted full binary tree in which each internal vertex corresponds to a
decision.

Eg 7: The following decision tree shows how 3 numbers a, b and c can be arranged in
order.
Is a > b?
Yes  No
Is b > c? Is b > c?
 
Yes No Yes No
Is a > c? Is a > c?
   
a>b>c c>b>a
Yes No Yes No

   
a>c>b c>a>b b>a>c b>c>a

14
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS

Fig. 26: A decision tree


Exercise 4.4
1. Refer to Exercise 4.2 & 4.3. For the graph in Q2, give a spanning tree rooted at vertex
F. Label all the levels and state the height of the tree.

2. Refer to Exercise 4.2 & 4.3. For the graph in Q3, give an example of a spanning tree
rooted at vertex e and determine its height.

3 a) If a graph G is connected and has exactly two vertices/nodes of odd degree, then
there is a/an _____________ path in G.
b) A tree with n nodes contains _______ edges.
c) The highest level of a tree is called the ________ of the tree.
d) The nodes of a tree that has no offsprings are called the _______ of the tree.

4 Given A = {1,2,3,4,5,6,7} and R = {(2,1),(2,3),(2,7),(3,4),(4,5),(4,6)}, a relation on


A.
i) Show that R is a tree.
ii) Sketch a rooted tree R and determine its root, leaves and height.

5. R is a relation on A. Determine if R is a tree. If yes, state its root.


a. A = {a,b,c,d,e}, R = {(a,d),(b,c),(c,a),(d,e)}
b. A = {1,2,3,4,5,6}, R = {(1,2),(1,3),(4,5),(4,6)}

6. Draw a full binary tree for each of the following algebraic expression.
a) b) [2a*(b - 5k)](m - 4)7

c) d)

15

You might also like