Skip to content

Commit eb91529

Browse files
authored
Update readme.md
1 parent 4fd6b92 commit eb91529

File tree

1 file changed

+16
-5
lines changed
  • Competitive Coding/Graphs/Topological Sort

1 file changed

+16
-5
lines changed
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
### Topological Sort
2+
3+
--------------------------------------
4+
5+
#### Algorithm Steps
6+
7+
18
MAX holds the maximum number of vertices possible in the graph, if you want more than 100 vertices chnge the value of MAX on line 4.
29
The first function called in the main is the create_graph(), which creates i.e. stores every edge along with its direction present in the graph.
10+
311
After this we calculate the in degree for each vertex and store it in the array indegree[i].
4-
If for any vertex the in-degree is 0 , it signifies that all the prerequisites of that vertex are considered and it is safe to be added in the queue
12+
If for any vertex the in-degree is 0 , it signifies that all the prerequisites of that vertex are considered and it is safe to be added in the queue.
13+
514
Then a loop continues till the queue is empty or count==total vertices.
6-
Inside the loop a vertex is deleted from the queue and all the outgoing edges are considered ,as the indegree of all the destination vertices
7-
with this particular vertex(deleted vertex) as origin is decremented by 1.
15+
Inside the loop a vertex is deleted from the queue and all the outgoing edges are considered ,as the indegree of all the destination vertices with this particular vertex(deleted vertex) as origin is decremented by 1.
16+
817
After the loop is completed it is checked if the count==total vertices.
9-
If yes a proper topological sort obtained is printed else it can be concluded that there exists a cycle in the graph and topological sort can't
10-
be obtained.
18+
19+
If yes a proper topological sort obtained is printed else it can be concluded that there exists a cycle in the graph and topological sort can't be obtained.
20+
21+

0 commit comments

Comments
 (0)