TOPOLOGICAL SORTING
• Topological sort of a directed acyclic graph (DAG) G is defined as a
linear ordering of its nodes in which each node comes before all
nodes to which it has outbound edges.
• Every DAG has one or more number of topological sorts.
• A topological sort of a DAG G is an ordering of the vertices of G such
that if G contains an edge (u, v), then u appears before v in the
ordering.
• Topological sort is possible only on directed acyclic graphs that do
not have any cycles.
• For a DAG that contains cycles, no linear ordering of its vertices is
possible.
• In simple words, a topological ordering of a DAG G is an ordering of
its vertices such that any directed path in G traverses the vertices in
increasing order.
Topological Sorting
Algorithm
The two main steps involved in the topological sort algorithm include:
Selecting a node with zero in-degree
Deleting N from the graph along with its edges
Step 1: Find the in-degree INDEG(N) of every node in the graph
Sep 2: Enqueue all the nodes with a zero in-degree
Step 3: Repeat Steps 4 and 5 until the QUEUE is empty
Step 4:Remove the front node N of the QUEUE by
setting FRONT = FRONT + 1
Step 5:Repeat for each neighbor M of node N:
Delete the edge from N to M by setting
INDEG(M) = INDEG(M) – 1
IF INDEG(M) = , then Enqueue M, that is,
add M to the rear of the queue
[END OF INNER LOOP]
[END OF LOOP]
Step 6: Exit
Contd..
• We will use a QUEUE to hold the nodes with
zero in-degree.
• The order in which the nodes will be deleted
from the graph will depend on the sequence
in which the nodes are inserted in the QUEUE.
Then, we will use a variable INDEG, where
INDEG(N) will represent the in-degree of node
N.
Example
• Consider a directed acyclic graph G given
below. We use the algorithm given above to
find a topological sort T of G. The steps are
given as below:( Refer the Notes)
BI- CONNECTIVITY
• A vertex v of G is called an articulation point, if removing v along with the
edges incident on v, results in a graph that has at least two connected
components.
• A bi-connected graph is defined as a connected graph that has no
articulation vertices. That is,
• bi-connected graph is connected and non-separable in the sense that even
if we remove any vertex from the graph, the resultant graph is still
connected. By definition,
– A bi-connected undirected graph is a connected graph that cannot be broken
into disconnected pieces by deleting any single vertex.
•
– In a bi-connected directed graph, for any two vertices v and w, there are two
directed paths from v to w which have no vertices in common other than v and
w.
Contd..
Note that the graph is not a bi-connected graph, as deleting vertex C from
the graph results in two disconnected components of the original graph
As for vertices, there is a related concept for edges.
An edge in a graph is called a bridge if removing that edge results in a disconnected graph.
Also, an edge in a graph that does not lie on a cycle is a bridge.
This means that a bridge has at least one articulation point at its end, although it is not
necessary that the articulation point is linked to a bridge.