Professional Documents
Culture Documents
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
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
1
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS
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
2
R=
1 3
4
Fig. 5. Relation and digraph
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?
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
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.
a) b)
b
a b
G: H: a c e
c
e d
d
4
MAT 110/210 CHAPTER 4 GRAPHS & DIGRAPHS
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)}
(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
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.
Eg 3:
a b a b a b
G: c H1: c H2: c
d e d d e
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
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?
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.
· ·
· · · · · ·
· · · · ·
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
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.
e
c b
4. Find a connected spanning subgraph with minimum edges for the graph in Q1 to
Q3.
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.
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
· · · Level 4
(leaves)
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.
G: a
b
c d e
f
Fig. 24
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.
Note: Labeled trees used to represent algebraic expressions are full binary trees.
–
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
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.
6. Draw a full binary tree for each of the following algebraic expression.
a) b) [2a*(b - 5k)](m - 4)7
c) d)
15