1 / 169

Completing Kosaraju’s Algorithm Introduction to Greedy Algorithms Scheduling Monday, July 7th

Completing Kosaraju’s Algorithm Introduction to Greedy Algorithms Scheduling Monday, July 7th. Announcements. Scoryst : Annotate which pages answer which problems. OH room B24A: A is the desk number. The room is Gates B24. Night office hours: Yiming : Thursday 7- 9pm

Download Presentation

Completing Kosaraju’s Algorithm Introduction to Greedy Algorithms Scheduling Monday, July 7th

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. Completing Kosaraju’s Algorithm Introduction to Greedy Algorithms Scheduling Monday, July 7th

  2. Announcements • Scoryst: Annotate which pages answer which problems. • OH room B24A: A is the desk number. The room is Gates B24. • Night office hours: • Yiming: Thursday 7-9pm • Billy: Wednesdays 7-9pm • Slides are posted on the website on the schedule tab.

  3. Last Wednesday DAGs Topological Sorting Strongly Connected Components

  4. Outline For Today Complete Kosaraju’s Algorithm Interesting Phenomenon About Shortest Paths And Connected Components Introduction to Greedy Algorithms Scheduling Problem Variant 1 & Greedy Algorithm 1 Scheduling Problem Variant 2 & Greedy Algorithm 2

  5. Outline For Today Complete Kosaraju’s Algorithm Interesting Phenomenon About Shortest Paths And Connected Components Introduction to Greedy Algorithms Scheduling Problem Variant 1 & Greedy Algorithm 1 Scheduling Problem Variant 2 & Greedy Algorithm 2

  6. Recap: DAGs • Job Scheduling in Operating Systems wc grep job2 tee job1 cat awk echo

  7. DAG Terminology • source: no incoming edges • sink: no outgoing edges wc grep job2 tee job1 cat awk echo

  8. Topological Sorting of A DAG Input: CS 106B CS 107 CS 110 Output: CS 106A CS 143 OR CS 109 CS 103 CS 161 106A 103 161 107 143 110 106B 109 106A 106B 103 109 161 143 107 110 OR… Output is not unique

  9. Topological Sorting Algorithm #1 proceduretopologicalSort1(DAG G): letresult empty list while G is not empty: 1. letv be a source node in G 2. add v to result 3. remove v from G returnresult/reverse Note: You can also pick a sink iteratively!

  10. Pseudocode TS Algorithm #2 (Using DFS) proceduretopologicalSort2(DAG G): run DFS(G) & put each finished vertex into an array in reverse order Runtime = Runtime of DFS = O(n + m) Correctnessdue to Key lemma about finishing times: If u  v, then f[u] > f[v]

  11. Recap: Strongly Connected Components SCC1 SCC2 L A J I D F E SCC3 B K H G C SCC4

  12. Two-tiered Structure SCC1 SCC2 SCC3 Claim: GSCC has to be a DAG! SCC4

  13. Kosaraju’s Algorithm: High-level Goal Use BFS/DFS to peel off the components by label propagation by picking start nodes from sink SCCs iteratively.

  14. Goal: Use BFS/DFS to Peel-off SCCs L I J A D E F C K H B G

  15. Goal: Use BFS/DFS to Peel-off SCCs E E L I J A D F C K H B G

  16. Goal: Use BFS/DFS to Peel-off SCCs F E E E L I J A D C K H B G

  17. Goal: Use BFS/DFS to Peel-off SCCs F E E E E L I J A D C G K H B

  18. Goal: Use BFS/DFS to Peel-off SCCs F E E E E L I J A D C G K H B

  19. Goal: Use BFS/DFS to Peel-off SCCs F E E E E L I J A D C G K H B

  20. Goal: Use BFS/DFS to Peel-off SCCs F E E E E L I J A D C G K H B

  21. Goal: Use BFS/DFS to Peel-off SCCs F E E E E L C D J I A G K H B B

  22. Goal: Use BFS/DFS to Peel-off SCCs F E E E E L D A J I G K H C B B B

  23. Goal: Use BFS/DFS to Peel-off SCCs F E E E E L D A J I G K H C B B B

  24. Goal: Use BFS/DFS to Peel-off SCCs F E E E E L D A J I G K H C B B B

  25. Goal: Use BFS/DFS to Peel-off SCCs F E E E E L D J I G A A K H C B B

  26. Goal: Use BFS/DFS to Peel-off SCCs F E E E E D L J I G A A A A K H C B B

  27. Goal: Use BFS/DFS to Peel-off SCCs F E E E E D L I J G A A A K C A B H B

  28. Goal: Use BFS/DFS to Peel-off SCCs F E E E E D L I J G A A A K C A B H B

  29. Goal: Use BFS/DFS to Peel-off SCCs F E E E E D L I J G A A A K C A B H B

  30. Goal: Use BFS/DFS to Peel-off SCCs F E E E E D L I J G A A A K C A B H B

  31. Goal: Use BFS/DFS to Peel-off SCCs F E E E I E D I L J G A A A K C A B H B

  32. Goal: Use BFS/DFS to Peel-off SCCs F E E E I E D I L G A J A I A K C A B H B

  33. Goal: Use BFS/DFS to Peel-off SCCs F E E E I E D I L G A J A I A C I A B K H B

  34. Goal: Use BFS/DFS to Peel-off SCCs F E E E E D I G A L J A I I I A C I A B K H B

  35. Goal: Use BFS/DFS to Peel-off SCCs F F E E E E E E I E E D I G G A L J A I I A C I A B K H B

  36. Goal: Use BFS/DFS to Peel-off SCCs F E E E I E D I G A L J A I I A C I A B K H B

  37. Goal: Use BFS/DFS to Peel-off SCCs F E E E I E D I G A L J A I I A C I A B K H B

  38. Goal: Use BFS/DFS to Peel-off SCCs F E E E I E D I G A L J A I I A C I A B K H B

  39. How To Pick The Source Nodes? Run DFS on Grev and pick source nodes in decreasing order of finishing times

  40. Kosaraju’s Algorithm procedure kosarajusSCC(DAG G): 1. run DFS on Grevand compute finishing times f 2. run DFS/BFS in G: pick start vertices by decreasing f times from the first DFS propagate the ID of each new start vertex during traversal Run-time: O(n + m)!

  41. DFS & Finishing Times on Grev L I J A D E F C K H B G

  42. DFS & Finishing Times on Grev E L I J A D F C K H B G

  43. DFS & Finishing Times on Grev E L I J A D F C G K H B

  44. DFS & Finishing Times on Grev F E L I J A D C G K H B

  45. DFS & Finishing Times on Grev F 1 E L I J A D C G K H B

  46. DFS & Finishing Times on Grev F 1 E 2 L I J A D C G K H B

  47. DFS & Finishing Times on Grev F 1 E 2 D L I J A C G K H B

  48. DFS & Finishing Times on Grev F 1 E 2 D L I J C G A K H B

  49. DFS & Finishing Times on Grev F 1 E 2 D L I J C G A K B H

  50. DFS & Finishing Times on Grev F 1 E 2 D L I J C G A K B 3 H

More Related