Professional Documents
Culture Documents
Algo Lecture11 GraphsTheory 08052024 010112pm
Algo Lecture11 GraphsTheory 08052024 010112pm
Algo Lecture11 GraphsTheory 08052024 010112pm
What is a graph?
• A set of vertices (or nodes) linked by edges
1
3
2 5
4
• Mathematically, we often write G = (V,E)
V: set of vertices, so |V| = number of vertices
E: set of edges, so |E| = number of edges
Graphs
• A graph G (sometimes called networks) consists of
two things:
(i) A set V = V(G) whose elements are called vertices,
points, or nodes of G.
(ii) A set E = E(G) of unordered pairs of distinct
vertices called edges of G.
• Vertices “u” and “v” are said to be adjacent if there is
an edge e = {u, v} joining them.
• the edge “e” is said to be incident on each of its
vertices u and v.
3
Example of a graph
4
Examples
6
Various types of graphs
• Connected/disconnected graphs
5
0 -2
9
Complete, regular and bipartite graphs
• A graph G is said to be complete if every vertex in G
is connected to every other vertex in G.
A graph G is regular of degree k or k-regular if every
vertex has degree k. (I.e every vertex has equal
number of edges)
• A graph G is said to be bipartite if its vertices V can
be partitioned into two subsets M and N such that
each edge of G connects a vertex of M to a vertex of
N.
• By a complete bipartite graph, we mean that each
vertex of M is connected to each vertex of N.
10
Graphs.G1
Graphs.G2
14
Directed graphs
15
Degrees of digraph
• The outdegree of a vertex v of G, written outdeg(v), is
the number of arcs beginning at v, and the indegree of
v, written indeg(v), is the number of arcs ending at v.
each arc begins and ends at a vertex.
• Theorem: The sum of the outdegrees of the vertices
of a digraph G equals the sum of the indegrees of the
vertices, which equals the number of edges in G.
16
Adjacency matrix of digraph
X Y Z W
No. of 1’s in A is X
equal to no. of Y
edges, row total Z
and col. Gives the W
indegree and
outdegree, resp. 17
Adjacency list
In graph theory, an adjacency list is the representation of all edges or arcs in
a graph as a list.
Connectivity of digraphs
• There are three types of connectivity in a directed graph G:
• (i) G is strongly connected or strong if, for any pair of vertices
u and v in G, there is a path from u to v; and a path from v to
u, that is, each is reachable from the other.
• (ii) G is unilaterally connected or unilateral if, for any pair of
vertices u and v in G, there is a path from u to v or a path from
v to u, that is, one of them is reachable from the other.
• (iii) G is weakly connected or weak if there is a undirected
path between any pair of vertices u and v in G.
19
Digraphs and relations
• The relation R is reflexive if every node has a loop.
• The relations R is symmetric if arcs are bidirectional.
• The relation R is transitive if for any sequence of
consecutive arcs, there is a single arc from the first to
the last node.
20
Digraphs and relations
21
Paths and connectivity
• A path in a graph G consists of an alternating sequence
of vertices and edges of the form;
v0, e1, v1, e2, v2, ………., en-1, vn-1 , еn, vn
• where each edge ei contains the vertices vi-1 and vi
(which appear on the sides of edge ei in the sequence).
• The path is said to be closed if v0 = vn. Otherwise, we say
the path is from v0 to vn, or between v0 and vn, or
connects v0 to vn. A simple path is a path in which all
vertices are distinct.
• Length of a path is the number of edges in the path.
• A graph G is connected if there is a path between any two
of its vertices
22
Eulerian circuit vs Hamiltonian circuit
• A Hamiltonian circuit in a graph G, named after the
nineteenth-century Irish mathematician William
Hamilton A805-1865), is a closed path that visits
every vertex in G exactly once.
• Eulerian circuit traverses every edge exactly once,
but may repeat vertices, while a Hamiltonian circuit
visits each vertex exactly once but may repeat edges.
• An Euler circuit for G is a circuit that contains every vertex and every edge of G.
That is, an Euler circuit is a sequence of adjacent vertices and edges in G that starts
and ends at the same vertex, uses every vertex of G at least once, and every edge
exactly once.
23
HAMILTON PATHS & CIRCUITS