Lec 35graph
Lec 35graph
Visit: tshahab.blogspot.com
1
Graph Definitions
A graph G is denoted by G = (V, E) where
V is the set of vertices or nodes of the graph
E is the set of edges or arcs connecting the vertices in V
Each edge E is denoted as a pair (v,w) where v,w V
For example in the graph below
2 V = {1, 2, 3, 4, 5, 6}
1
E = {(1, 2) (2, 5) (3, 6) (4, 6)
3
(5, 6)}
This is an example of an
unordered or undirected
6 4
graph
5
2
Graph Definitions (contd.)
If the pair of vertices is ordered then the
graph is a directed graph or a di-graph
2
1 3 Here,
V = {1, 2, 3, 4, 5, 6}
6 4 E = {(1, 2) (2, 5) (5, 6) (6,
3) (6, 4)}
5
Vertex v is adjacent to w iff (v,w) E
Sometimes an edge has another component called a
weight or cost. If the weight is absent it is assumed to be 1
3
Graph Definitions: Path
A path is a sequence of vertices w1, w2, w3, ....wn
such that (wi, wi+1) E
Length of a path = # edges in the path
A loop is an edge from a vertex onto itself. It is
denoted by (v, v)
A simple path is a path where no vertices are
repeated along the path
A cycle is a path with at least one edge such that
the first and last vertices are the same, i.e. w1 = wn