algorithms
play

Algorithms R OBERT S EDGEWICK | K EVIN W AYNE 4.2 T OPOLOGICAL S - PowerPoint PPT Presentation

Algorithms R OBERT S EDGEWICK | K EVIN W AYNE 4.2 T OPOLOGICAL S ORT Algorithms F O U R T H E D I T I O N R OBERT S EDGEWICK | K EVIN W AYNE http://algs4.cs.princeton.edu Topological sort demo Run depth-first search. Return vertices


  1. Algorithms R OBERT S EDGEWICK | K EVIN W AYNE 4.2 T OPOLOGICAL S ORT Algorithms F O U R T H E D I T I O N R OBERT S EDGEWICK | K EVIN W AYNE http://algs4.cs.princeton.edu

  2. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. tinyDAG7.txt 0 0 7 11 0 5 0 2 2 2 5 5 1 1 0 1 3 6 3 5 3 4 3 3 4 4 5 2 6 4 6 0 6 6 3 2 a directed acyclic graph 2

  3. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 postorder 2 2 5 5 1 v marked[] 0 T 1 F 3 3 4 4 2 F 3 F 4 F 6 6 5 F 6 F visit 0: check 1, check 2, and check 5 3

  4. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 postorder 2 2 5 5 1 1 v marked[] 0 T 1 T 3 3 4 4 2 F 3 F 4 F 6 6 5 F 6 F visit 1: check 4 4

  5. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 postorder 2 2 5 5 1 1 v marked[] 0 T 1 T 3 3 4 4 2 F 3 F 4 T 6 6 5 F 6 F visit 4 5

  6. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 postorder 4 2 2 5 5 1 1 1 v marked[] 0 T 1 T 3 3 4 4 2 F 3 F 4 T 6 6 5 F 6 F 4 done 6

  7. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 0 postorder 4 1 2 2 5 5 1 1 v marked[] 0 T 1 T 3 3 4 2 F 3 F 4 T 6 6 5 F 6 F 1 done 7

  8. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 postorder 4 1 2 2 5 5 1 v marked[] 0 T 1 T 3 3 4 2 F 3 F 4 T 6 6 5 F 6 F visit 0: check 1, check 2, and check 5 8

  9. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 postorder 4 1 2 2 5 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 F 4 T 6 6 5 F 6 F visit 2 9

  10. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 0 postorder 4 1 2 2 2 5 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 F 4 T 6 6 5 F 6 F 2 done 10

  11. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 postorder 4 1 2 2 5 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 F 4 T 6 6 5 F 6 F visit 0: check 1, check 2, and check 5 11

  12. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 postorder 4 1 2 2 5 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 F 4 T 6 6 5 T 6 F visit 5: check 2 12

  13. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 postorder 4 1 2 2 5 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 F 4 T 6 6 5 T 6 F visit 5 13

  14. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 0 postorder 4 1 2 5 2 5 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 F 4 T 6 6 5 T 6 F 5 done 14

  15. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 postorder 4 1 2 5 0 2 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 F 4 T 6 6 5 T 6 F 0 done 15

  16. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 2 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 F 4 T 6 6 5 T 6 F check 1 16

  17. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 2 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 F 4 T 6 6 5 T 6 F check 2 17

  18. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 2 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 T 4 T 6 6 5 T 6 F visit 3: check 2, check 4, check 5, and check 6 18

  19. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 2 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 T 4 T 6 6 5 T 6 F visit 3: check 2, check 4, check 5, and check 6 19

  20. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 2 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 T 4 T 6 6 5 T 6 F visit 3: check 2, check 4, check 5, and check 6 20

  21. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 2 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 T 4 T 6 6 5 T 6 F visit 3: check 2, check 4, check 5, and check 6 21

  22. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 2 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 T 4 T 6 6 5 T 6 T visit 6: check 0 and check 4 22

  23. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 2 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 T 4 T 6 6 5 T 6 T visit 6: check 0 and check 4 23

  24. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 6 2 5 1 v marked[] 0 T 1 T 3 3 4 2 T 3 T 4 T 6 6 5 T 6 T 6 done 24

  25. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 6 3 2 5 1 v marked[] 0 T 1 T 3 4 2 T 3 T 4 T 6 5 T 6 T 3 done 25

  26. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 6 3 2 5 1 v marked[] 0 T 1 T 3 4 2 T 3 T 4 T 6 5 T 6 T check 4 26

  27. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 6 3 2 5 1 v marked[] 0 T 1 T 3 4 2 T 3 T 4 T 6 5 T 6 T check 5 27

  28. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 postorder 4 1 2 5 0 6 3 2 5 1 v marked[] 0 T 1 T 3 4 2 T 3 T 4 T 6 5 T 6 T check 6 28

  29. Topological sort demo ・ Run depth-first search. ・ Return vertices in reverse postorder. 0 0 postorder 4 1 2 5 0 6 3 2 2 5 5 1 1 topological order 3 6 0 5 2 1 4 3 3 4 4 6 6 done 29

Recommend


More recommend