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

Graphs

The document discusses different types of graphs including undirected graphs, directed graphs, simple graphs, and complete graphs. It also discusses graph terminology such as adjacent vertices, incident edges, and cycles. Finally, it covers different ways to represent graphs including adjacency lists and adjacency matrices.

Uploaded by

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

Graphs

The document discusses different types of graphs including undirected graphs, directed graphs, simple graphs, and complete graphs. It also discusses graph terminology such as adjacent vertices, incident edges, and cycles. Finally, it covers different ways to represent graphs including adjacency lists and adjacency matrices.

Uploaded by

hriaz2600
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

INTRODUCTION TO GRAPHS

What is Graph (Undirected Graph)?

INTRODUCTION TO GRAPHS
► A graph G = (V, E) consists of
o V – a nonempty set of vertices (or nodes) ⇛ represents by point
 Infinite vertex set – Infinite graph
 Finite vertex set – Finite graph
o E – a set of Edges ⇛ represents by line segments or curve
 Each edge has either one or two vertices associated with it,
called its endpoints. An edge is said to connect its endpoint.
o The way we draw a graph is arbitrary as long as the correct
connections between vertices are depicted. Avoid crossing edge.

► Example of graph – refer Figure: b


• 3 vertices ⇛ V = {a, b, c}
e2 e3
• 3 edges ⇛ E = {e1, e2, e3} e1
= {{a, a}, {a, b}, {b, c}} a c
What is Simple Graph?

INTRODUCTION TO GRAPHS
► A simple graph contains no loop or parallel edges
o No loop ⇛ Each edge connects two different vertices
o No parallel ⇛ No two edges connect the same pair of vertices

► Example of simple graph and not a simple graph


e1
c
b b b

e2 e3 e2 e3
e1 e2 e3

a a c
e1 c
a
simple graph not a simple graph not a simple graph
What is Directed Graph?

INTRODUCTION TO GRAPHS
► A graph directed (or digraph) (V, E) consists of
o V – a nonempty set of Vertices (or nodes) ⇛ represents by point
o E – a set of directed Edges ⇛ represents by line segments or
curve
 Each directed edge associated with an ordered pair of
vertices (u, v), which said to start at u and end at v.

► Simple directed graph – a directed graph with no loops and no


multiple directed edges
► Directed multigraph – a directed graph with multiple directed edge
► Mixed graph – a graph with both directed and undirected edges
b
e2 e3
► Example of directed graph
e1
a c
Adjacent and Incident

GRAPH TERMINOLOGY
• Two vertices u and v in an undirected graph G are called
adjacent (or neighbors) in G if u and v are endpoints of
an edge of G.

• If the edge e is associated with {u, v}, e is called incident


with the vertices u and v. (e connect u and v)

• Example:
b
– a and b are adjacent
e2 e3
– a and c not adjacent
e1
– e2 incident with a and b a c
Complete Graph

GRAPH TERMINOLOGY
• The Complete Graph on n vertices, denoted by Kn, is the
simple graph that contains exactly one edge between each
pair of distinct vertices.
• Example: the graph Kn for n = 1, 2, 3, 4, 5, 6 are shown below:


K1 K2 K3 K4 K5
Cycles

GRAPH TERMINOLOGY
• The Cycle Cn, n ≥ 3, consists of n vertices v1, v2, … vn and
edges {v1, v2}, {v2, v3}, …, {vn-1,vn} and {vn, v1}.
• Example: the Cn for 3 ≤ n ≤ 6.

C3 C4 C5 C6
GRAPHS CAN HAVE CYCLES BUT TREES DON’T
Representing Graphs

REPRESENTING GRAPH AND GRAPH ISOMORPHISM


• Adjacency List
– Specify the vertices that are adjacent to each vertex of
the graph

• Adjacency Matrix
– Represents graph by a matrix based on the adjacency
of vertices
Adjacency List (UnDirected Graph)

REPRESENTING GRAPH AND GRAPH ISOMORPHISM


• Specify the vertices that are adjacent to each vertex of
the graph

Adjacency List
Vertex Adjacent Vertices
b
a b, c, e
a c
b a
c a, d, e
e d d c, e
e a, c, d
Adjacency List (Directed Graph)

REPRESENTING GRAPH AND GRAPH ISOMORPHISM


• List all the vertices that are the terminal vertices of
edges starting at each vertex of the graph

Adjacency List
a b
Initial Vertex Terminal Vertices
a b, d
b c
c b
d c
d b, c, d
EXERCISE

REPRESENTING GRAPH AND GRAPH ISOMORPHISM


1. Use an adjacency list to represent the given graph

a b c a b

FIGURE 1 FIGURE 3

d e f
c d e
b
a

FIGURE 2 FIGURE 4
d
a c b c
e
d
Adjacency Matrix (Simple UnDirected Graph)

REPRESENTING GRAPH AND GRAPH ISOMORPHISM


• If A = [aij] is the adjacency matrix for simple undirected
graph G with n vertices v1, v2, …, vn, then
1 if {vi , v j } is an edge of G A is
aij   symmetric
0 otherwise
• EXAMPLE: Use adjacency matrix to represent the graph
below.
a b c d e
b 0 1 1 0 1 a
1 0 0 0 0  b
a c

A  1 0 0 1 1 c
 
0 0 1 0 1 d
1 0 1 1 0  e
e d
Adjacency Matrix (not Simple UnDirected Graph)

REPRESENTING GRAPH AND GRAPH ISOMORPHISM


• Aij is represent by the number of edges that associated to
[ai , aj]
• A loop at a vertex represent by 1
• When multiple edges are present, adjacency matrix is no
longer a zero-one matrix.
• The matrix is symmetric
• EXAMPLE: Use adjacency matrix to represent the graph
below. a b c d
0 3 0 1 a

a b 3 0 1 0  b
A
0 1 1 2 c
c
  d
d 1 0 2 0
Adjacency Matrix (Directed Graph)

REPRESENTING GRAPH AND GRAPH ISOMORPHISM


• Aij is represent by the number of edges from ai to aj
• A loop at a vertex represent by 1
• When multiple edges are present, adjacency matrix is no
longer a zero-one matrix.
• The matrix is not symmetric
• EXAMPLE: Use adjacency matrix to represent the graph
below.
a b c d
a b
0 1 0 0 a
0 0 2 0  b
A
0 0 0 0 c
 d
1 1 1 1
d c
EXERCISE

REPRESENTING GRAPH AND GRAPH ISOMORPHISM


2. Represent the graph with an adjacency matrix

a b c a b

FIGURE 1 FIGURE 3

d e f
c d e
b
a

FIGURE 2 FIGURE 4
d
a c b c
e
d
Draw Graph from Adjacency Matrix

REPRESENTING GRAPH AND GRAPH ISOMORPHISM


• An adjacency matrix of a graph is based on the ordering
chosen for the vertices.
• There are n! different adjacency matrices for a graph with n
vertices, because there are n! different ordering of n vertices

• EXAMPLE: Draw a graph with the given adjacency matrix

a b c d e
b
0 1 1 0 1 a
1 0 0 0 0  b
 a c
A  1 0 0 1 1 c
 
0 0 1 0 1 d
1 0 1 1 0  e e d
EXERCISE

REPRESENTING GRAPH AND GRAPH ISOMORPHISM


3. Draw a graph with the given adjacency matrix

a) b)
0 1 1 0 0 3 0 2
1 3 1 
0 0 1  0 1
A A
1 0 0 1 0 1 1 2
   
0 1 1 0 2 1 2 0

c)
0 1 0 0
0 0 2 0 
A
0 0 0 0
 
1 1 1 1
1 2 3 4 E
0 3 0 2 1 X
3 0 1 1  2
A
A M
0 1 1 2 3 P
  LE
2 1 2 0 4

1 2 3 4
1
0 1 0 0
0 0 2 0  2
A
0 0 0 0 3
 
1 1 1 1 4

You might also like