I used standart Topological sort algorithm, but if node==5000 it says stack overflow, any one know how to do it without recursion.
Thanks
Topological Sort
Moderator: Board moderators
-
- Experienced poster
- Posts: 161
- Joined: Tue Oct 25, 2005 8:38 pm
- Location: buet, dhaka, bangladesh
ya, it can be done using indegree. indegree indicates number of edges coming into u from any other vertices.
1. output and remove any node u, elements of V, such that indegree = 0.
2. decrease all indegree[v] by one, if (u,v) is an edge.
3. jump to 1 untill all node has been removed.
Note that, you will always find at least one node of indegree 0 if there exists no cycle in the graph.
1. output and remove any node u, elements of V, such that indegree = 0.
2. decrease all indegree[v] by one, if (u,v) is an edge.
3. jump to 1 untill all node has been removed.
Note that, you will always find at least one node of indegree 0 if there exists no cycle in the graph.
ishtiak zaman
----------------
the world is nothing but a good program, and we are all some instances of the program
----------------
the world is nothing but a good program, and we are all some instances of the program