Lecture 9
Graphs
Definition
simple graph G= (V, E) consists of vertices, V, anonempty set of vertices, and E, a set of unorderedpairs of distinct elements of V called edges.
Types of Graphs
Types of Graphs
- no arrows
- no loops
- can't have multiple edges joining vertices
A simple graph
Definition
multigraph G=(V, E) consists of a set V of vertices,a set E of edges, and a function f from E to {{u, v} |u, v  V,  v}. The edges e1 and e2 are calledmultiple or parallel edges if f(e1) = f(e2).
Types of Graphs
Types of Graphs
A multigraph
 No loop is allowed.
 Multiple edges are allowed.
Definition
pseudograph G = (V, E) consists of a set V ofvertices, a set E of edges, and a function f from E to{{u, v} | u, v  V}. An edge is a loop if f(e) = {u, v} forsome v  V.
Types of Graphs
Types of Graphs
pseudo-graph
Definition
directed graph (V, E) consists of set of set ofvertices and set of edges that are orderedpairs of elements of V.
Types of Graphs
Types of Graphs
directed-graph-1
 Loops, ordered pairs orthe same element, areallowed.
  Multiple edges in thesame direction betweentwo vertices are notallowed.
A directed graph
Definition
directed multigraph (V, E) consists of set Vof vertices, set of edges, and function f from Eto {(u, vu, v  V}. The edges e1 and e2 aremultiple edges if f(e1f(e2).
Types of Graphs
Types of Graphs
directed-multigraph-1
Loops, ordered pairs orthe same element, areallowed.
 
   Multiple edges in thesame direction betweentwo vertices are allowed.
A directed multigraph
Summary
Types of Graphs
Type
Edges
Multiple edgesallowed?
Loopsallowed?
Simplegraph
Undirected
No
No
Multigraph
Undirected
Yes
No
Pseudograph
Undirected
Yes
Yes
Directedgraph
Directed
No
Yes
Directedmultigraph
Directed
Yes
Yes
Exercises
Round-robin tournament
There will be an edge (a, b) from team a toteam b, if team a beats team b.
Graph Terminology
Adjacent:
Two vertices u and v in an undirected graph G arecalled adjacent (or neighbours) if {u, v} is an edgeof G.
If e = {u, v} the edge e is called incident withu and v. The edge e is also said to connect uand v. The vertices u and v are calledendpoints of the edge {u, v}.
15
a
b
c
d
e
e1
e2
e3
e4
e5
e6
Vertex a is adjacent to b because there is an edge e1that connects vertices a and b.
 
Edge e4 is incident with vertices a and d.
Edge e4 connect vertices a and d.
Edge e6 connect vertices e and e.
Graph Terminology
The degree of a vertex in an undirectedgraph is the number of edges incident with it,except that a loop at a vertex contributestwice to the degree of that vertex.
The degree of the vertex v is denoted bydeg(v).
18
Example 1
What are the degrees of the vertices in thefollowing graph?
b
a
c
f
e
d
g
deg(a) =
deg(b) =
deg(c) =
deg(d) =
deg(e) =
deg(f) =
deg(g) =
2
4
4
3
1
4
0
Vertex of degree zero is calledisolated
19
The Handshaking Theorem
Theorem:
Suppose the vertices of graph G are v1, v2, …,vn, where is a non-negative integer, thenthe total degree of G
=deg(v1) + deg(v2) + …. + deg(vn)
 
= 2 (the number of edges of G).
The handshaking Theorem
Total number of edges: 4
Total degree: 1 + 1 + 1 + 5 = 8.
Handshaking theorem: 2 x 4 = 8.
test2.png
21
Example 2
How many edges are there in a graph withseven vertices each of degree four?
The sum of the degrees of the vertices is
4x7 = 28.
2e = 28
e = 14.
Representing Graphs
Three methods
1.Adjacency lists
2.Adjacency matrices
3.Incidence matrices
Representing Graphs
Adjacency lists
b
a
c
d
e
A simplegraph
UNABLE TO REPRESENT MULTIPLE-EDGES.
Representing Graphs
A directed graph
Representing Graphs
Adjacency matrices
Suppose that G=(V, E) is a simple graph where |V|=n.Suppose that the vertices of G are listed arbitraryas v1,v2,..., vn. The adjacency matrix A of G is a n×nzero-one matrix with 1 as its (i, j)th entry when viand vj are adjacent, and 0 as its entry when theyare not adjacent.
Representing Graphs-Adjacency matrix
a
b
c
d
G
Adjacencymatrix for G
Representing Graphs-Adjacency matrix
Representing multigraph or pseudograph
Adjacency matrix-directed graph
0    1    0    0    1
0    1    0    0    0
1    0    0    1    0
0    0    1    0    1
0    0    0    0    0
a     b    c    d    e
a
b
c
d
e
Adjacency Matrix
Representing Graphs
Incidence Matrices
Let G=(V, E) be an undirected graph. Supposethat v1, v2, ..., vn are the vertices and e1, e2, ...,em are the edges G. The incidence matrix of G isa nx m matrix M=[mij], where
Representing Graphs
incidence-matrix
Incidence Matrix
Connectivity
Definition
Let n be a nonnegative integer and G a directedmultigraph. A path of length n from u to v in Gis a sequence of edges e1, e2, ..., en of G suchthat f(e1)=(x0, x1), f(e2)=(x1, x2), f(en)=(xn-1, xn),where x0=u and xn=v.
Connectivity
Definition
When there are non multiple edges in thedirected graph, this path is denoted by itsvertex sequence x0, x1, x2, ..., xn.
A path of length greater than zero that beginsand ends at the same vertex is called a circuitor cycle.
A path or circuit is simple if it does not containthe same edge more than once.
Connectivity
a, d, c, f, e is a simple path of length 4 since {a, d}, {d, c},{c, f}, and {f, e} are all edges and no repeated edge.
b, c, f, e, b is a circuit of length 4 since this path begins andends at b.
The path a, b, e, d, a, b is of length 5, is not simple since itcontains the edge {a, b} twice.
Is a, d, e, a, b  a simple path?
Paths from v0 to v7
1. v0 v1 v2 v5 v7
2. v0 v1 v4 v5 v4 v5  v7
3. v0 v3 v4 v6 v7
Which path(s) is (are)simple?
Simple path vs simple circuit
Connectedness in Undirected Graphs
Definition
An undirected graph is called connected if thereis a path between every pair of distinct verticesof the graph.
G is connected,whereas H is not.
Connectedness in Undirected Graphs
Theorem
There is a simple path between every pair of distinctvertices of a connected undirected graph.
Connectedness in Directed Graphs
Definition
A directed graph is strongly connected if there isa path from a to b and from b to a whenever aand b are vertices in the graph.
Definition
A directed graph is weakly connected if there isa path between any two vertices in theunderlying undirected graph.
Connectedness in Directed Graphs
is strongly connected because there is pathbetween any two vertices in this directed graph.
The graph is not strongly connected. There is nodirected path from to in this graph. is weaklyconnected since there is path between any twovertices in the underlying undirected graph of H.
Euler and Hamilton Paths
Questions
Can we travel along the edges of graph startingat a vertex and returning to it by traversingeach edge of the graph exactly once?
Can we travel along the edges of a graphstarting at a vertex and returning to it whilevisiting each vertex of the graph exactly once?
Euler Paths and Circuits
Definition
An Euler circuit in a graph G is a simple circuitcontaining every edge of G.
An Euler path in G is a simple path containingevery edge in G.
Note: Both in Euler path and Euler circuit, each edgecannot be repeated more than once.
If graph has Euler circuit then it must has Euler path,the opposite could be false.
Euler Paths and Circuits
Example
Necessary and sufficient conditions for euler circuits and paths
Theorem 1
A connected multigraph has an Euler circuit if andonly if each of its vertices has even degree.
Theorem 2
A connected multigraph has an Euler path but notan Euler circuit if and only if it has exactly twovertices of odd degree.
Euler Paths and Circuits
For graph G1, the degree for each vertex in thisgraph is even, hence this graph contain Euler circuit.
For graph G2, the degree for vertex e, a are odd, sothere is no Euler circuit.
G1
G2
Euler Paths and Circuits
G1 contains exactly two vertices of odd degree, b and d.Hence it has an Euler path that must have b and d as its endpoints.  E.g.:
b, c, d, a, b, d.
G2 also contains exactly two vertices of odd degree, d and b.One of the Euler path is b, a, g, b, c, g, f, c, f, e, d.
Hamilton Paths and Circuits
Definition
A path x0, x1, ..., xn-1, xn in the graph G = (V, E) iscalled a Hamilton path if V={x0, x1, ..., xn-1, xn} andxixj for 0 ijn
A circuit x0, x1, ..., xn-1, xn , x0(with n > 1) in a graphG = (V,E) is called a Hamilton circuit
if x0, x1, ..., xn-1 Hamilton path.
Graph G1 has a Hamilton circuit: a, b, c, d, e, a.
There is no Hamilton circuit in G2 because edge (a, b)will be always use twice. E.g.: d, c, b, a, b, d.  G2 hasHamilton path, a, b, c, d.
Sufficient conditions for hamilton path circuit
A graph with a vertex of degree 1 cannothave a Hamilton circuit.
If each vertex in a graph is adjacent to everyother vertex there is always a Hamiltoncircuit.