Skip to content

It is a Python implementation of Kahn's algorithm for topological sorting of graphs. It uses Networkx library for performing graph operations.

Notifications You must be signed in to change notification settings

dani2819/Efficient-implementation-of-topological-sorting-of-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Implementation-of-topological-sorting-of-graph

It is a Python implementation of Kahn's algorithm for topological sorting of graphs. It uses Networkx library for performing graph operations. Topological sorting for Directed Acyclic Graph (DAG) is a linear ordering of vertices such that for every directed edge uv, vertex u comes before v in the ordering. Topological Sorting for a graph is not possible if the graph is not a DAG.

Pseudocode of Kahn's Algorithm

L ← Empty list that will contain the sorted elements

S ← Set of all nodes with no incoming edges

while S is non-empty do

    remove a node n from S

    add n to tail of L

    for each node m with an edge e from n to m do

        remove edge e from the graph

        if m has no other incoming edges then

            insert m into S



    if graph has edges then

        return error (graph has at least one cycle)

    else 

        return L (a topologically sorted order)

About

It is a Python implementation of Kahn's algorithm for topological sorting of graphs. It uses Networkx library for performing graph operations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages