Lecture 8 Graph
Lecture 8 Graph
Use of Graphs
• Let,
• V = {1, 2, 3, 4}
• E = {(1,2), (2,3), (1,4)} 33
Khulna 4CTG
4
Graphs
• A graph is a bunch of vertices (or nodes) represented by circles which
are connected by edges, represented by line segments
Graphs
Definition
{1,4}
SET OF VERTICES
V = { 1, 2, 3, 4 }
SET OF EDGES
E = { (1, 2), (1, 3), (2, 3), (2, 4), (3, 4), (1, 4) }
L23 6
Simple Graphs
Definition
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.
Dhaka Raj
Bangkok NY
Multi-graphs
Definition
Graphs that may have multiple edges connecting the same vertices are
called multigraphs.
Dhaka Raj
Bangkok NY
Undirected Graphs
Dhaka
Raj
Bangkok NY
Pseudo graphs
Definition
Edges that connect a vertex to itself are called loops. A graph with loop
(self-loop) is called pseudo graph.
Dhaka
Raj
Bangkok NY
Directed Graphs
• Dhaka to Rajshahi
• Dhaka to Chapai
• Rajshahi to Dhaka
• No Chapai to Dhaka, but Chapai to Rajshahi
Dhaka
Rajshahi
Chapai
A Directed Graph
Definition
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.
• Mixed Graphs
Types of Graphs
Undirected Graphs: Adjacent
Definition
Vertices are adjacent if they are the endpoints of the same edge or they
are connected by the same edge.
1 2
Adjacent of 1 : 2 and 4
Adjacent of 2 : 1 and 3
Adjacent of 3 : 2 3 4
Undirected Graphs Terminology
Adjacent Vertices (Neighbors)
16
Undirected Graphs
Terminology
e1
1 e2 2
e3 e4 e5
3 e6 4
A: 1 is adjacent to 2 and 3
2 is adjacent to 1 and 3
3 is adjacent to 1 and 2
4 is not adjacent to any vertex
L23 17
Undirected Graphs
Terminology
e1
1 e2 2
e3 e4 e5
3 e6 4
e3 e4 e5
3 e6 4
L23 19
Undirected Graphs: Degree
Definition
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).
1 2
deg (1) : 2
deg (3) : 1
deg (4) : 3 3 4
Directed Graphs : Adjacent
Definition
1 2
Adjacent of 1 : 2 and 4
Adjacent of 2 : 1 and 3
Adjacent of 3 : 2 3 4
Directed Graphs : Degree
1 2
In degree :
Out degree:
3 4
Directed Graphs : Degree
Definition
Oriented Degree
when Edges Directed
The in-degree of a vertex (deg-) counts the number of edges
that stick in to the vertex.
The out-degree (deg+) counts the number sticking out.
1 3
L23 25
Any Questions?