notes65

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

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

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.

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

View Full Document
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
never be zero; if (i < n) { //not all vertices are sorted, return topological sort not possible. return NULL;

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue.

### 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
Ask a homework question - tutors are online