TopologicalSort

# TopologicalSort - Topological Sort The goal of a...

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

Topological Sort The goal of a topological sort is given a list of items with dependencies, (ie. item 5 must be completed before item 3, etc.) to produce an ordering of the items that satisfies the given constraints. In order for the problem to be solvable, there can not be a cyclic set of constraints. (We can't have that item 5 must be completed before item 3, item 3 must be completed before item 7, and item 7 must be completed before item 5, since that would be an impossible set of constraints to satisfy.) We can model a situation like this using a directed acyclic graph. Given a set of items and constraints, we create the corresponding graph as follows: 1) Each item corresponds to a vertex in the graph. 2) For each constraint where item a must finish before item b, place a directed edge in the graph starting from the vertex for item a to the vertex for item b. This graph is directed because each edge specifically starts from one vertex and goes to another. Given the fact that the constraints must be acyclic, the resulting graph will be as well. Here is a simple situation: A B (Imagine A standing for waking up, | | B standing for taking a shower, V V C standing for eating breakfast, and C D D leaving for work.) Here a topological sort would label A with 1, B and C with 2 and 3, and D with 4.

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

View Full Document
Let's consider the following subset of CS classes and a list of prerequisites: CS classes: COP 3223, COP 3502, COP 3330, COT 3100, COP 3503, CDA 3103, COT 3960 (Foundation Exam), COP 3402, and COT 4210. Here are a set of prerequisites:
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 11/09/2009.

### Page1 / 7

TopologicalSort - Topological Sort The goal of a...

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

View Full Document
Ask a homework question - tutors are online