Data Structure & Algorithm in Java

⌘K
  1. Home
  2. Docs
  3. Data Structure & Alg...
  4. Graphs
  5. Topological Sort

Topological Sort

image 50
fig: Directed Acyclic Graph (DAG)
  1. Identify vertices with in-degree 0 (vertices with no incoming edges).
  2. Select a vertex with in-degree 0.
  3. Remove the selected vertex and its outgoing edges.
  4. Repeat steps 1-3 until all vertices are included.
  5. If at any point there are no vertices with in-degree 0, and the graph is not empty, the graph contains a cycle (not a DAG).
image 48
There can be more than one topological sorting for a graph. Another topological sorting of the following graph is (7 5 6 4 2 3 1 0)
Screenshot 2024 02 23 162144
image 49
  • Task Scheduling
  • Build Systems
  • Network Dependency Analysis
  • Task Execution Order
Tags

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *