Graphs 2.8 - DAGs and Topological Ordering A directed...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: DAGs and Topological Ordering A directed acyclic graph (DAG) is a digraph that has no directed cycles A topological ordering of a digraph is a numbering D v1 , …, vn B of the vertices such that for every edge (vi , vj), we have i < j C DAG G A Example: in a task scheduling digraph, a topological ordering is a task sequence that satisfies the precedence constraints v4 D v2 Theorem B A digraph admits a topological ordering if and only if it is a DAG A - 91 - v5 E v3 C v1 CSE 2011 Prof. J. Elder E Topological ordering of G Last Updated: 4/1/10 10:16 AM Topological (Linear) Order underwear socks pants shoes underwear pants socks shoes socks CSE 2011 Prof. J. Elder underwear pants shoes - 92 - Last Updated: 4/1/10 10:16 AM Topological (Linear) Order underwear socks pants shoes Invalid Order socks shoes pants underwear CSE 2011 Prof. J. Elder - 93 - Last Updated: 4/1/10 10:16 AM Algorithm for Topological Sorting Note: This algorithm is different than the one in Goodrich-Tamassia Method TopologicalSort(G) H G // Temporary copy of G n G.numVertices() while H is not empty do Let v be a vertex with no outgoing edges Label v n n n-1 Remove v from H //as well as edges involving v CSE 2011 Prof. J. Elder - 94 - Last Updated: 4/1/10 10:16 AM Linear Order a h i j k b c d e g l f Pre-Condition: A Directed Acyclic Graph (DAG) Post-Condition: Find one valid linear order Algorithm: •Find a terminal node (sink). •Put it last in sequence. •Delete from graph & repeat V i =1 CSE 2011 Prof. J. Elder ….. l - 95 - () i =O V Running time: O(|V|) 2 Can we do better? Last Updated: 4/1/10 10:16 AM ...
View Full Document

This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

Page1 / 5

Graphs 2.8 - DAGs and Topological Ordering A directed...

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

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