0% found this document useful (0 votes)
357 views8 pages

Topological Sorting

The document discusses topological sorting of directed acyclic graphs (DAGs). It defines topological sorting as a linear ordering of the nodes in a DAG where each node comes before all nodes it has outbound edges to. It provides that every DAG has one or more topological sorts. It also notes that topological sorting is only possible for DAGs without cycles, as cycles prevent a linear ordering. The document then outlines the basic algorithm for topological sorting which involves selecting nodes with zero in-degree and deleting them from the graph.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
357 views8 pages

Topological Sorting

The document discusses topological sorting of directed acyclic graphs (DAGs). It defines topological sorting as a linear ordering of the nodes in a DAG where each node comes before all nodes it has outbound edges to. It provides that every DAG has one or more topological sorts. It also notes that topological sorting is only possible for DAGs without cycles, as cycles prevent a linear ordering. The document then outlines the basic algorithm for topological sorting which involves selecting nodes with zero in-degree and deleting them from the graph.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy