Advanced Analysis of Algorithm: Course Instructor: Mirza Adnan Baig Week # 9
Advanced Analysis of Algorithm: Course Instructor: Mirza Adnan Baig Week # 9
Algorithm
Course Instructor: Mirza Adnan Baig
Week # 9
Introduction to Graph
What Is a Graph?
Z
7
Vertex & Edge
Vertex /Node
Basic Element
Drawn as a node or a dot.
Vertex set of G is usually denoted by V(G), or V or VG
Edge /Arcs
A set of two elements
Drawn as a line connecting two vertices, called end vertices, or
endpoints.
The edge set of G is usually denoted by E(G), or E or EG
Neighborhood
For any node v, the set of nodes it is connected to via an edge is called its
neighborhood and is represented as N(v)
Graph :Example
n:= 6 , m:=7
Vertices (V) :={1,2,3,4,5,6}
Edge (E) := {1,2},{1,5},{2,3},{2,5},{3,4},{4,5},{4,6}}
N(4) := Neighborhood (4) ={6,5,3}
Edge types:
Undirected;
E.g., distance between two cities, friendships…
Directed; ordered pairs of nodes.
E.g ,…
Directed edges have a source (head, origin) and target (tail,
destination) vertices
1 2 3
isolated vertex 4 5 6
Adjacent nodes
An edge where the two end vertices are the same is called a
loop, or a self-loop
Degree (Un Directed Graphs)
The degree of 5 is 3
Degree (Directed Graphs)
outdeg(1)=2 outdeg(2)=2
indeg(2)=2 indeg(1)=0
outdeg(3)=1
indeg(3)=4
Walk
d
walk: a path in which edges/nodes c
can be repeated.
a-b-d-a-b-c
A walk is considered to be Closed if
the starting vertex is the same as the
ending vertex, that is v0=vk. A walk
is considered Open otherwise.
Paths
Multiple
edges
loop
9
Adjacent, neighbors
• Two vertices are adjacent and are
neighbors if they are the endpoints of an
edge
• Example:
– A and B are adjacent
– A and D are not adjacent
A B
C D
11
Connected and Disconnected
• Connected : There exists at least one
path between two vertices
• Disconnected : Otherwise
• Example:
– H1 and H2 are connected
– H3 is disconnected
a b a b
H1 c
H2 H3 c
e
d d
e d
Graph Theory 13
Types of Graph
Complete Graph
• Complete Graph: A simple graph in which every
pair of vertices are adjacent
• If no of vertices = n, then there are n(n-1) edges
14
Sparse/Dense Graph
15
Finite Graph, Null Graph
12
Simple Graph
Multiple
edges loop
10
Directed Graph (digraph)
16
Weighted Graph
Weighted graph is a graph for which each edge
has an associated weight, usually given by a
weight function w: E R.
1.2 2
1 2 3 1 2 3
.2 5 3
1.5 1
.5 .3
4 5 6
4 5 6
.5
17
Planar Graph
18
Complement
Complement of G: The complement G’ of
a simple graph G :
– A simple graph
– V(G’) = V(G)
– E(G’) = { uv | uv E(G) }
u
u
y
y v v
G
G’
w x w
x
19
Subgraphs
21
Subgraphs
G c
e d
a b
a b
c H3 c
H1 H2
d e d
e d
22
Trees