1 / 18

Recall: Digraphs

E. D. C. B. A. Recall: Digraphs. A digraph is a graph whose edges are all directed Short for “directed graph” Applications one-way streets flights task scheduling. Digraph Application. Scheduling: edge (a,b ) means task a must be completed before b can be started. ics21. ics22.

diana-cobb
Télécharger la présentation

Recall: Digraphs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. E D C B A Recall: Digraphs • A digraph is a graph whose edges are all directed • Short for “directed graph” • Applications • one-way streets • flights • task scheduling

  2. Digraph Application • Scheduling: edge (a,b) means task a must be completed before b can be started ics21 ics22 ics23 ics51 ics53 ics52 ics161 ics131 ics141 ics121 ics171 The good life ics151

  3. DFS • In digraphs we traverse edges only along their direction • In the directed DFS algorithm, we can distinguish four types of edges • discovery edges • back edges • forward edges • cross edges • A directed DFS starting a a vertex s determines the vertices reachable from s E D C B A

  4. Reachability • DFS tree rooted at v: vertices reachable from v via directed paths E D E D C A C F E D A B C F A B

  5. DAGs and Topological Ordering D E • A directed acyclic graph (DAG) is a digraph that has no directed cycles • A topological ordering of a digraph is a numbering v1 , …, vn of the vertices such that for every edge (vi , vj), we have i < j • Example: in a task scheduling digraph, a topological ordering a task sequence that satisfies the precedence constraints Theorem A digraph admits a topological ordering if and only if it is a DAG B C A DAG G v4 v5 D E v2 B v3 C v1 Topological ordering of G A

  6. Topological Sorting • Number vertices, so that (u,v) in E implies u < v 1 A typical student day wake up 3 2 eat study computer sci. 5 4 nap more c.s. 7 play 8 write c.s. program 6 9 work out make cookies for professors 10 11 sleep dream about graphs

  7. Algorithm for Topological Sorting • Running time: ? MethodTopologicalSort(G) H G // Temporary copy of G n G.numVertices() whileH is not emptydo Let v be a vertex with no outgoing edges Label v  n n  n - 1 Remove v from H

  8. Topological Sorting Algorithm using DFS • Run DFS • Topological sort = Reverse order of Finish Order List • O(n+m) time.

  9. Topological Sorting Example

  10. Topological Sorting Example 9

  11. Topological Sorting Example 8 9

  12. Topological Sorting Example 7 8 9

  13. Topological Sorting Example 6 7 8 9

  14. Topological Sorting Example 6 5 7 8 9

  15. Topological Sorting Example 4 6 5 7 8 9

  16. Topological Sorting Example 3 4 6 5 7 8 9

  17. Topological Sorting Example 2 3 4 6 5 7 8 9

  18. Topological Sorting Example 2 1 3 4 6 5 7 8 9

More Related