notes65

notes65 - CS251 Class Notes Spring 2006 Ibrahim Shareef...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS251 Class Notes Spring 2006 Ibrahim Shareef Topological Sort It is the sorting of the vertices such that if there is an edge i , j ( i ---> j ) then i should appear in the sorting before j. --A topological sort is useful for scheduling of events that depend on each other. A topological sort would be a possible schedule of execution.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithm: Topological sorting Input: A digraph G with n vertices Output: An array "sorted" with the vertices in topological order //We use a stack to store the vertices with no dependencies (Could also use a queue or other container) stack = {} //Compute "in degree" of vertices for each edge (v, w) v -----> w indegree[w]++; } //Put vertices without incident edges (no dependencies) in stack for all v in G do if indegree[v] == 0; push v in stack
Background image of page 2
never be zero; if (i < n) { //not all vertices are sorted, return topological sort not possible. return NULL;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

notes65 - CS251 Class Notes Spring 2006 Ibrahim Shareef...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online