Strongly Connected Components in A Graph Using Tarjan Algorithm
Strongly Connected Components in A Graph Using Tarjan Algorithm
Strongly Connected Components in A Graph Using Tarjan Algorithm
net/publication/295010370
CITATIONS READS
0 1,215
1 author:
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Syed aqeel Awais on 18 February 2016.
Definition: Let G be a directed graph. Suppose that for each pair of vertices v,w in G,
there exists a path p1: v w and p2: w v. Then G is said to be strongly connected. [1]
Lemma: Let G=(v,e) be a directed graph. We may define an equivalence relation on the
set of vertices as follows: two vertices v and w are equivalent if there is a closed path
p: v v which contains w. Let the distinct equivalence classes under this relation be vi ,
1<=i<=n. Let Gi= (vi,ei) where ei ={(v,w) e|v,wvi}.
I. Each Gi is strongly connected
II. No Gi is a proper subgraph of a strongly connected subgraph of G. [1]
A graph can be defined as the combination of vertices and the edges associated
between them.
G= (V, E)
Where V is the number of vertices and E represents the edges. Generally A directed can
be seen as below in figure,[2]
2. Representation of Graphs
Graphs can be represented in two ways by using the adjacency matrix and the lists. In
this project link list have been used for checking the adjacency between different nodes.
The list can be represented as follows, [2]
3. Algorithm Description
BEGIN
INTEGER i;
PROCEDURE STRONGCONNECT (v);
BEGIN
LOWLINK (v) := NUMBER (v) :=i :=i + 1;
put v on stack of points;
FOR w in the adjacency list of v DO
BEGIN
4. Time Analysis
The time required by algorithm is linear in space and time. When the search has been
started, the values of the LOWLINK has been evaluated and for every search the found
vertex has been placed on the stack data structure and this has been removed only once
from the stack. A Boolean array has been used for checking if the found vertex is already
visited or not. As every operation has been done once, the strongly connected
component algorithm is linearly bound in both the space and time (|V| + |E|). [1]
5. Implementation
A link list has been considered for checking the adjacency of different vertices with each
other. First, we declare an object for the graph class and initialized the constructor with
given number of vertices.
In the first graph we have entered five vertices and traverse over all of them using the
link list, list<int> *adj,
Now we push this vertex into the stack to store this value, stack<int>*st and push this
value as st->push(u). The next step is to check the adjacency with this vertex by
traversing the whole link list as adj[u].begin to the adj[u].end. Moreover, the vertices
which are adjacent to each other add an edge between them using the function
addedge,
We have kept Boolean array “bool stackmember[]” for checking if the vertex has already
been visited in the stack or not which makes it very fast checking for the visited and unvisited
vertices and to keep track on them.
If the vertex is not already a stack member, we just keep on adding the tree edges between
them and the low value of the vertex would be defined as,
If the vertex has already been visited then the back edge has been added and the low value of
the is defined as per it is defined in the tarjan’s algorithm,
As we move ahead we use the recursive function for finding the adjacency as deep as possible
and found the vertices as below,
The strongly connected components are:
Another graph is provided for finding the strongly connected components in that graph,
The values which has same values of low link has formed the strongly connected
component.