cit 327: principles of graph theory lecture note by dr. oyelami … · 2020-04-20 · dr. oyelami...

29
CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami M. O. What is a Graph? A graph is a pictorial representation of a set of objects where some pairs of objects are connected by links. The interconnected objects are represented by points termed as vertices, and the links that connect the vertices are called edges. Formally, a graph is a pair of sets (V, E), where V is the set of vertices and E is the set of edges, connecting the pairs of vertices. For example, consider the graph below: In the above graph, V = {a, b, c, d, e} E = {ab, ac, bd, cd, de} GRAPH THEORY – FUNDAMENTALS Point: A point is a particular position in a one-dimensional, two-dimensional, or three-dimensional space. ● a Line: A Line is a connection between two points. It can be represented with a solid line. Vertex: A vertex is a point where multiple lines meet. It is also called a node. Similar to points, a vertex is also denoted by an alphabet. ● a

Upload: others

Post on 09-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

CIT 327: Principles of Graph Theory

Lecture Note

By

Dr. Oyelami M. O.

What is a Graph?

A graph is a pictorial representation of a set of objects where some pairs of objects are connected by links.

The interconnected objects are represented by points termed as vertices,

and the links that connect the vertices are called edges. Formally, a graph is a pair of sets (V, E), where V is the set of vertices and

E is the set of edges, connecting the pairs of vertices.

For example, consider the graph below:

In the above graph,

V = {a, b, c, d, e} E = {ab, ac, bd, cd, de}

GRAPH THEORY – FUNDAMENTALS

Point: A point is a particular position in a one-dimensional, two-dimensional,

or three-dimensional space. ● a

Line: A Line is a connection between two points. It can be represented with

a solid line.

Vertex: A vertex is a point where multiple lines meet. It is also called a node.

Similar to points, a vertex is also denoted by an alphabet.

● a

Page 2: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Edge: An edge is the mathematical term for a line that connects two vertices.

Many edges can be formed from a single vertex. Without a vertex, an edge

cannot be formed. There must be a starting vertex and an ending vertex for

an edge.

Here, ‘a’ and ‘b’ are the two vertices and the link between them is called

an edge.

A graph ‘G’ is defined as G = (V, E) where V is a set of all vertices and E is a

set of all edges in the graph.

ab, ac, cd, and bd are the edges of the graph.

Similarly, a, b, c, and d are the vertices of the graph.

Loop: In a graph, if an edge is drawn from vertex to itself, it is called a loop.

V is a vertex for which it has an edge (V, V) forming a loop

Degree of Vertex

In a simple graph with n number of vertices, the degree of any vertex is:

deg(v) ≤ n – 1 ∀ v ∈ G

Degree of Vertex in an Undirected Graph

An undirected graph has no directed edges.

For example, consider the following:

Page 3: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

deg(a) = 2, as there are 2 edges meeting at vertex ‘a’.

deg(b) = 3, as there are 3 edges meeting at vertex ‘b’.

deg(c) = 1, as there is 1 edge formed at vertex ‘c’

So ‘c’ is a pendent vertex. deg(d) = 2, as there are 2 edges meeting at vertex ‘d’.

deg(e) = 0, as there are 0 edges formed at vertex ‘e’.

So ‘e’ is an isolated vertex.

Degree of Vertex in a Directed Graph

In a directed graph, each vertex has an indegree and an outdegree.

Indegree of a Graph

Indegree of vertex V is the number of edges which are coming into the

vertex V.

Notation: deg+(V).

Outdegree of a Graph

Outdegree of vertex V is the number of edges which are going out from the

vertex V.

Notation: deg-(V). Consider the following as an example:

Page 4: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Pendent Vertex

By using degree of a vertex, we have a two special types of vertices. A

vertex with degree one is called a pendent vertex.

Vertex ‘a’ and vertex ‘b’ each has degree as one which are also called as

the pendent vertices.

Isolated Vertex

A vertex with degree zero is called an isolated vertex.

Page 5: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Adjacency

Here are the norms of adjacency: In a graph, two vertices are said to be adjacent, if there is an edge

between the two vertices. In a graph, two edges are said to be adjacent, if there is a common vertex

between the two edges.

Example

In the graph above: ‘a’ and ‘b’ are the adjacent vertices, as there is a common edge ‘ab’

between them.

‘a’ and ‘d’ are the adjacent vertices, as there is a common edge ‘ad’

between them.

‘ab’ and ‘be’ are the adjacent edges, as there is a common vertex ‘b’ between them.

‘be’ and ‘de’ are the adjacent edges, as there is a common vertex ‘e’

between them.

Parallel Edges

In a graph, if a pair of vertices is connected by more than one edge, then

those edges are called parallel edges.

In the above graph, ‘a’ and ‘b’ are the two vertices which are connected by

two edges ‘ab’ and ‘ab’ between them. So it is called as a parallel edge.

Page 6: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Multi Graph

A graph having parallel edges is known as a Multigraph.

Since ‘c’ and ‘d’ have two parallel edges between them, it a Multigraph.

In the above graph, the vertices ‘b’ and ‘c’ have two edges. The vertices ‘e’

and ‘d’ also have two edges between them. Hence it is a Multigraph.

Degree Sequence of a Graph

If the degrees of all vertices in a graph are arranged in descending or

ascending order, then the sequence obtained is known as the degree

sequence of the graph.

Example

Vertex a b c d e

Connecting

to b, c a, d a, d

c, b,

e d

Degree 2 2 2 3 1

Page 7: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

GRAPH BASIC PROPERTIES

Graphs come with various properties which are used for characterization of

graphs depending on their structures.

Distance between Two Vertices It is number of edges in a shortest path between Vertex U and

Vertex V. If there are multiple paths connecting two vertices, then the

shortest path is considered as the distance between the two vertices.

Notation: d(U,V)

Example

Here, the distance from vertex ‘d’ to vertex ‘e’ or simply ‘de’ is 1 as there

is one edge between them. There are many paths from vertex ‘d’ to vertex ‘e’:

o da, ab, be

o df, fg, ge

o de

o df, fc, ca, ab, be

o da, ac, cf, fg, ge

Eccentricity of a Vertex

The maximum distance between a vertex to all other vertices is considered as the eccentricity of vertex.

Notation: e(V)

In the above graph, the eccentricity of ‘a’ is 3. The distance from ‘a’ to ‘b’ is 1 (‘ab’),

Page 8: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

from ‘a’ to ‘c’ is 1 (‘ac’),

from ‘a’ to ‘d’ is 1 (‘ad’), from ‘a’ to ‘e’ is 2 (‘ab’-‘be’) or (‘ad’-‘de’),

from ‘a’ to ‘f’ is 2 (‘ac’-‘cf’) or (‘ad’-‘df’), from ‘a’ to ‘g’ is 3 (‘ac’-‘cf’-‘fg’) or (‘ad’-‘df’-‘fg’).

So the eccentricity is 3, which is a maximum from vertex ‘a’ from the

distance between ‘ag’ which is maximum. In other words,

e(b) = 3 e(c) = 3

e(d) = 2 e(e) = 3

e(f) = 3 e(g) = 3

Connected Graph: A graph G is said to be connected if there exists a path between every pair of vertices.

Disconnected Graph: A graph G is disconnected, if it does not contain at

least two connected vertices.

Page 9: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

The two components are independent and not connected to each other.

Hence it is called disconnected graph.

Radius of a Connected Graph

The minimum among all the maximum distances between a vertex to all other vertices is considered as the radius of the Graph G.

From all the eccentricities of the vertices in a graph, the radius of the connected graph is the minimum of all those eccentricities.

Notation: r(G)

Example

In the above graph r(G) = 2, which is the minimum eccentricity for ‘d’.

Diameter of a Graph

The maximum eccentricity from all the vertices is considered as the diameter of the Graph G.

The maximum among all the distances between a vertex to all other vertices is considered as the diameter of the Graph G.

Notation: d(G)

Example: In the above graph, d(G) = 3; which is the maximum eccentricity.

Central Point

If the eccentricity of a graph is equal to its radius, then it is known as the central point of the graph.

If e(V) = r(V), then ‘V’ is the central point of the Graph ’G’.

Example: In the example graph, ‘d’ is the central point of the graph. e(d) = r(d) = 2

Page 10: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Centre

The set of all central points of ‘G’ is called the centre of the Graph. Example: In the example graph, {‘d’} is the centre of the Graph.

Circumference The number of edges in the longest cycle of ‘G’ is called as the

circumference of ‘G’.

Example

In the example graph, the circumference is 6, which we derived from the

longest cycle a-c-f-g-e-b-a or a-c-f-d-e-b-a.

Girth

The number of edges in the shortest cycle of ‘G’ is called its Girth. Notation: g(G).

Example: In the example graph, the Girth of the graph is 4, which we

derived from the shortest cycle a-c-f-d-a or d-f-g-e-d or a-b-e-d-a

Sum of Degrees of Vertices Theorem

TYPES OF GRAPHS

Page 11: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Null Graph: A graph having no edges is called a Null Graph.

In the above graph, there are three vertices named ‘a’, ‘b’, and ‘c’, but

there are no edges among them. Hence it is a Null Graph.

Trivial Graph: A graph with only one vertex is called a Trivial Graph.

● a

Non-Directed Graph

Directed Graph: In a directed graph, each edge has a direction.

Page 12: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Simple Graph: A graph with no loops and no parallel edges is called a simple graph.

The maximum number of edges possible in a simple graph with ‘n’ vertices

is nC2 where nC2 = n(n – 1)/2. The number of simple graphs possible with ‘n’ vertices =

Example

The maximum number of simple graphs with n=3 vertices:

These 8 graphs are as shown below:

Page 13: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Regular Graph: A graph G is said to be regular, if all its vertices have the

same degree. In a graph, if the degree of each vertex is ‘k’, then the graph is called a ‘k-

regular graph’.

Example

In both the graphs, all the vertices have degree 2. They are called 2-

Regular Graphs

Complete Graph: If a vertex should have edges with all other vertices,

then it called a complete graph.

Page 14: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Cycle Graph: A simple graph with ‘n’ vertices (n >= 3) and ‘n’ edges is called

a cycle graph if all its edges form a cycle of length ‘n’. If the degree of each vertex in the graph is two, then it is called a

Cycle Graph. Notation: Cn

Example

Take a look at the following graphs:

Graph I has 3 vertices with 3 edges which is forming a cycle ‘ab-bc-ca’. Graph II has 4 vertices with 4 edges which is forming a cycle ‘pq-qs-sr-rp’.

Graph III has 5 vertices with 5 edges which is forming a cycle ‘ik-km-ml-

lj-ji’. Hence all the given graphs are cycle graphs.

Wheel Graph: A wheel graph is obtained from a cycle graph Cn-1 by adding a

new vertex.

That new vertex is called a Hub which is connected to all the vertices of Cn.

Notation: Wn

No. of edges in Wn = No. of edges from hub to all other vertices + No. of edges from all other nodes in cycle graph without a hub.

= (n–1) + (n–1)

Page 15: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

= 2(n–1)

Example

The following are all wheel graphs:

Cyclic Graph: A graph with at least one cycle is called a cyclic graph.

Acyclic Graph: A graph with no cycles is called an acyclic graph.

Page 16: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Bipartite Graph: A simple graph G = (V, E) with vertex partition V = {V1,

V2} is called a bipartite graph if every edge of E joins a vertex in V1 to a vertex in V2.

In general, a Bipartite graph has two sets of vertices, let us say, V1 and V2,

and if an edge is drawn, it should connect any vertex in set V1 to any vertex in set V2.

Complete Bipartite Graph: A bipartite graph ‘G’, G = (V, E) with partition V = {V1, V2} is said to be a complete bipartite graph if every vertex in V1 is

connected to every vertex of V2.

Page 17: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

If |V1| = m and |V2| = n, then the complete bipartite graph is denoted by

Km, n. Km, n has (m+n) vertices and (mn) edges.

Km, n is a regular graph if m=n.

The maximum number of edges in a bipartite graph with n vertices is 𝑛2/4

Graph Search Methods Two standard ways to search for the vertices of a graph are:

i. Breadth-First Search (BFS) and

ii. Depth-First Search (DFS).

Although both search methods are popular, the depth-first method is used more frequently to obtain efficient graph algorithms. Breadth-First Search This is a method of starting at a vertex and identifying all vertices reachable from it. Consider the directed graph below:

Page 18: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Using the breadth-first search, we determine first al the vertices reachable from

vertex 1 by determining the set of vertices adjacent from 1. The set is {2,3,4}.

Next we determine the vertices not yet reached that are adjacent from vertices

{2,3,4}. The set is {5,6,7}.

The set of new vertices adjacent from vertices in {5,6,7} is {8,9}. No new

vertices are adjacent from a vertex in {8,9};

Therefore, {1,2,3,4,5,6,7,8,9} is the set of vertices reachable from vertex 1. This

method may be implemented using a queue.

The pseudocode is given below:

BreadthFirstSearch (v)

{

Label vertex v as reached.

Initialize Q to be a queue with only v in it.

While(Q is not empty)

{

Delete a vertex w from the queue.

Let u be a vertex (if any) adjacent from w.

while (u)

{

If (u has not been labeled)

{

Add u to the queue.

Label u as reached.

}

u = next vertex that is adjacent from w.

Fig 3.

Page 19: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

}

}

}

Depth-First Search (DFS)

This is similar to preorder traversal of a binary tree. The pseudocode for depth-first

search is:

DepthFirstSearch(v)

{

Label vertex v as reached.

For( each unreached vertex u from v) DepthFirstSearch(u);

}

To try DepthFirstSearch on the digraph in the figure above, if v = 1, then vertices 2,

3 and 4 are candidates for the first choice of u. Suppose that the first value assigned

to u is 2. A DFS from 2 is now initiated. Vertex 2 is marked as reached. The only

candidate for u now is vertex 5, and a DFS from 5 is initiated. Vertex 5 is marked as

reached, and then a DFS from 8 is initiated. Next, vertex 8 is marked. From 8 there

are no unreached adjacent vertices, so the algorithm backs up to vertex 5. There are

no new candidates for u here, so we back up to 2 and then to 1.

From 1, vertices 3 and 4 are candidates for u. If 4 is selected, a DFS from 4 is

initiated, and vertex 4 is marked as reached. Vertices 3, 6, 7 are now candidates for

u. If 6 is selected, when v=6, vertex 3 is the only candidate for u. A DFS from 3 is

initiated, and vertex 3 gets labeled as reached. No new vertices are adjacent from 3,

and we back up to vertex 6. No new vertices are adjacent from here, so we back up

to 4. From 4, we initiate a DFS with u=7. Next we reach vertex 9 from which there

are no new adjacent vertices. This time, we back up all the way to 1. As there are no

new vertices adjacent from 1, the algorithm terminates.

Page 20: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Representation of Unweighted Graphs

Unweighted graphs can be represented using

i. Adjacency matrices

ii. Array adjacency lists and

iii. Linked adjacency lists.

Adjacency Matrix

The adjacency matrix of an n-vertex graph G = (V, E) is an n x n matrix A. Each

element of A is either 0 or 1. If G is an undirected graph, then the elements of A are

defined as follows:

𝐴(𝑖, 𝑗) = { 1 𝑖𝑓 (𝑖, 𝑗)𝜖 𝐸 𝑜𝑟 (𝑗, 𝑖) 𝜖 𝐸0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

The adjacency matrix of

is

1 2 3 4

1 0 1 1 1

2 1 0 1 0

3 1 1 0 1

4 1 0 1 0

Page 21: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Array Adjacency Lists

In the array-adjacency-list representation of a graph, each adjacency list is

represented by using an array-based linear list representation rather than a chain. The

array adjacency list for the graph above in fig 2a is:

The adjacency list for vertex i is a linear list that includes all vertices adjacent from

i.

Linked Adjacency Lists

In an adjacency-list representation of a graph, we maintain an adjacency list for each

vertex of the graph. When these adjacency lists are represented as chains, we get the

linked-adjacency-list representation. Below is the linked adjacency list for the graph

in fig 2a:

Representation of Weighted Graphs

Weighted graphs are generally represented with schemes that are simple extensions

of those used for unweighted graphs. Cost-adjacency-matrix representation can be

used to represent a weighted graph. It uses a matrix C just like the adjacency-matrix

Page 22: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

representation does. If A(i,j) is 1, then C(i,j) is the cost (or weight) of the

corresponding edge. If A(i,j) is 0, then the corresponding edge is not present and

C(i,j) equals null. The cost-adjacency matrix for fig 2a could be the following:

Adjacency-list could also be used to represent a weighted graph from that of the

corresponding graph by using chains whose elements have two fields: vertex and

weight. Below is the adjacency list representation of fig 2a:

The first component of each node is the vertex and the second is weight.

Isomorphism

The word isomorphism comes from Greek roots, its meaning is roughly “equal

shapes.”

We say that two graphs are isomorphic if there is a function f that maps the vertex

set of one graph to the vertex set of the other; additionally, this function must be

a bijection (one-to-one and onto) and it must respect the edge-endpoint relation.

That is, if vi and vj are connected by some number of edges in the first graph then

f(vi) and f(vj) are connected by the same number of edges in the second.

Page 23: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

How to Detect Isomorphism

If two graphs have a different number of nodes, they cannot possibly be

isomorphic.

Two isomorphic graphs must have the same number of edges.

Clearly these conditions are not sufficient. Consider the two graphs in figure

below, they both have 5 vertices and 5 edges, but obviously there is something

different about them.

One feature that can be used to distinguish the graphs in the figure above is the

degrees of their vertices.

The degree of a vertex v in a graph G is the number of edges that are incident

with it.

(Note that since a loop is incident twice with the same vertex, it will add two to

the degree of that vertex.)

There is a vertex having degree 1 in the graph on the left in the figure, whereas

all the vertices in the right-hand graph have degree 2.

The number of cycles in each graph can also be used to determine isomorphic

graphs. The two graphs must have the same number of cycles.

A cycle in a graph is a path along the edges of G that begins and ends in the

same place and never hits a vertex (other than the initial one) more than once –

it must also not cross any edge more than once.

Exercise

Determine if the graphs below are isomorphic.

Page 24: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Solution:

The graphs G and H both have eight vertices and 10 edges.

They also both have four vertices of degree two and four of degree three.

Because these invariants (A property preserved by isomorphism of graphs is

called a graph invariant) all agree, it is still conceivable that these graphs are

isomorphic.

However, G and H are not isomorphic.

To see this, note that because deg(a) = 2 in G, a must correspond to either t , u,

x, or y in H, because these are the vertices of degree two in H.

However, each of these four vertices in H is adjacent to another vertices of degree

2 and 3 in H, but a is adjacent to two vertices of degree 3 in G.

Shortest-Path Problems

Many problems can be modeled using graphs with weights assigned to their

edges.

As an illustration, consider how an airline system can be modeled.

We set up the basic graph model by representing cities by vertices and flights

by edges.

Problems involving distances can be modeled by assigning distances between

cities to the edges.

Problems involving flight time can be modeled by assigning flight times to

edges.

Problems involving fares can be modeled by assigning fares to the edges.

Page 25: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

A Shortest-Path Algorithm

There are several different algorithms that find a shortest path between two

vertices in a weighted graph.

We will present a greedy algorithm discovered by the Dutch mathematician

Edsger Dijkstra in 1959.

The version described solves this problem in undirected weighted graphs

where all the weights are positive.

It is easy to adapt it to solve shortest-path problems in directed graphs.

Before giving a formal presentation of the algorithm, we will give an

illustrative example.

Example: What is the length of a shortest path between a and z in the weighted

graph shown below?

Page 26: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Solution

Although a shortest path is easily found by inspection, we will develop some ideas

useful in understanding Dijkstra’s algorithm. We will solve this problem by finding

the length of a shortest path from a to successive vertices, until z is reached.

The only paths starting at a that contain no vertex other than a are formed by adding

an edge that has a as one endpoint. These paths have only one edge. They are a, b of

length 4 and a, d of length 2. It follows that d is the closest vertex to a, and the

shortest path from a to d has length 2.

We can find the second closest vertex by examining all paths that begin with the

shortest path from a to a vertex in the set {a, d}, followed by an edge that has one

endpoint in {a, d} and its other endpoint not in this set. There are two such paths to

consider, a, d, e of length 5 and a, b of length 4. Hence, the second closest vertex to

a is b and the shortest path from a to b has length 4.

To find the third closest vertex to a, we need examine only the paths that begin with

the shortest path from a to a vertex in the set {a, d, b}, followed by an edge that has

one endpoint in the set {a, d, b} and its other endpoint not in this set. There are three

of such paths, a, b, c of length 7, a, b, e of length 7, and a, d, e of length 5. Because

the shortest of these paths is a, d, e, the third closest vertex to a is e and the length

of the shortest path from a to e is 5.

To find the fourth closest vertex to a, we need examine only the paths that begin

with the shortest path from a to a vertex in the set {a, d, b, e}, followed by an edge

that has one endpoint in the set {a, d, b, e} and its other endpoint not in this set.

There are two such paths, a, b, c of length 7 and a, d, e, z of length 6. Because the

shorter of these paths is a, d, e, z, the fourth closest vertex to a is z and the length of

the shortest path from a to z is 6.

Page 27: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

The algorithm is given below:

1. Mark all nodes unvisited. Create a set of all the unvisited nodes called the unvisited set.

2. Assign to every node a tentative distance value: set it to zero for our initial node and to infinity

for all other nodes. Set the initial node as current.

3. For the current node, consider all of its unvisited neighbours and calculate their tentative

distances through the current node. Compare the newly calculated tentative distance to the

current assigned value and assign the smaller one. For example, if the current node A is marked

with a distance of 6, and the edge connecting it with a neighbour B has length 2, then the

distance to B through A will be 6 + 2 = 8. If B was previously marked with a distance greater

than 8 then change it to 8. Otherwise, keep the current value.

4. When we are done considering all of the unvisited neighbours of the current node, mark the

current node as visited and remove it from the unvisited set. A visited node will never be

checked again.

5. If the destination node has been marked visited (when planning a route between two specific

nodes) or if the smallest tentative distance among the nodes in the unvisited set is infinity (when

planning a complete traversal; occurs when there is no connection between the initial node and

remaining unvisited nodes), then stop. The algorithm has finished.

6. Otherwise, select the unvisited node that is marked with the smallest tentative distance, set it

as the new "current node", and go back to step 3.

Page 28: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

Graph Partition

In mathematics, the graph partition problem is defined on data represented in

the form of a graph G = (V, E), with V vertices and E edges, such that it is possible

to partition G into smaller groups with specific properties.

Edges of the original graph that cross between the groups will produce edges in

the partitioned graph

For instance, a k-way partition divides the vertex set into k smaller groups.

A good partition is defined as one in which the number of edges running

between separated groups is small.

Uniform graph partition is a type of graph partitioning problem that consists of

dividing a graph into groups, such that the groups are of about the same size

and there are few connections between the groups.

Applications of Graph Partitioning

Important applications of graph partitioning include:

i. Scientific computing,

ii. Partitioning various stages of a VLSI design circuit

iii. Task scheduling in multi-processor systems.

iv. Recently, the graph partition problem has gained importance due to its

application for clustering and detection of cliques in social, pathological and

biological networks

Standard Graph Partitioning Approach

The standard approach is to model the problem and partition the vertices of the

graph into equally weighted sets so that the weight of the edges crossing between

sets is minimized.

Well-known software packages such as Chaco and METIS can be used for this

purpose.

Note that the graph partitioning problem is NP-hard, so these tools merely apply

heuristics to generate approximate solutions.

A Bipartite Graph Model

A bipartite graph, G (V1; V2; E.) is a special type of graph in which the vertices

are divided into two disjoint subsets, V1 and V2, and E is a subset of V1 X V2.

Page 29: CIT 327: Principles of Graph Theory Lecture Note By Dr. Oyelami … · 2020-04-20 · Dr. Oyelami M. O. What is a Graph? ... Formally, a graph is a pair of sets (V, E), where V is

So, no edge connects two vertices in the same subset; instead, all the edges

cross between V1 and V2.

The figure below shows the bipartite graph representation of a rectangular

matrix.

The sets V1 and V2 correspond to the row and column vertices, respectively.

Each row vertex in V1 is weighted with the number of non-zeros in its row; e.g.

row vertex r4 has a weight of one.

This weighting reflects the computational work required in the matrix-vector

product.

Fig. Rectangular matrix and Bipartite graph

This bipartite graph representation is most useful when the initial tasks are

logically distinct from the final tasks.

Although the bipartite model is good for describing two computational

operations, it is not able to accurately encode more. One possible generalization

is to use a k-partite graph in which the first set of vertices is connected to a second

set, which is connected to a third set, and so on.