network science
play

Network Science Depth-First Search Joao Meidanis University of - PowerPoint PPT Presentation

Network Science Depth-First Search Joao Meidanis University of Campinas, Brazil March 24, 2020 Summary Depth-First Search (DFS) Algorithm 1 Example 2 Applications 3 Meidanis (Unicamp) Network Science March 24, 2020 2 / 24 Depth-First


  1. Network Science Depth-First Search Joao Meidanis University of Campinas, Brazil March 24, 2020

  2. Summary Depth-First Search (DFS) Algorithm 1 Example 2 Applications 3 Meidanis (Unicamp) Network Science March 24, 2020 2 / 24

  3. Depth-First Search (DFS) Algorithm Meidanis (Unicamp) Network Science March 24, 2020 3 / 24

  4. Depth-First Search Needs: adjacency lists Provides: edge classification cycle detection topological sort Meidanis (Unicamp) Network Science March 24, 2020 4 / 24

  5. Algorithm — Core function DFS-Visit ( u , Adj ) for v in Adj[u] do if v not in parent then parent[v] ← u DFS-Visit ( v , Adj ) end if end for end function Meidanis (Unicamp) Network Science March 24, 2020 5 / 24

  6. Algorithm — Main function DFS ( V , Adj ) parent ← {} for v in V do if v not in parent then parent[v] ← None DFS-Visit ( v , Adj ) end if end for end function Meidanis (Unicamp) Network Science March 24, 2020 6 / 24

  7. Example Meidanis (Unicamp) Network Science March 24, 2020 7 / 24

  8. Example: directed graph a b c d e f g Meidanis (Unicamp) Network Science March 24, 2020 8 / 24

  9. Example: directed graph a b c d e f g Meidanis (Unicamp) Network Science March 24, 2020 9 / 24

  10. Example: directed graph a b c d e f g Meidanis (Unicamp) Network Science March 24, 2020 10 / 24

  11. Example: directed graph a b c d e f g Meidanis (Unicamp) Network Science March 24, 2020 11 / 24

  12. Example: directed graph a b c d e f g Meidanis (Unicamp) Network Science March 24, 2020 12 / 24

  13. Example: directed graph a b c d e f g Meidanis (Unicamp) Network Science March 24, 2020 13 / 24

  14. Example: directed graph a b c d e f g Meidanis (Unicamp) Network Science March 24, 2020 14 / 24

  15. Example: directed graph a b c d e f g Meidanis (Unicamp) Network Science March 24, 2020 15 / 24

  16. Example: directed graph a b c d e f g Meidanis (Unicamp) Network Science March 24, 2020 16 / 24

  17. Example: directed graph a b c d e f g Meidanis (Unicamp) Network Science March 24, 2020 17 / 24

  18. Example: directed graph a b c d e f Running time O ( V + E ) g linear time Meidanis (Unicamp) Network Science March 24, 2020 18 / 24

  19. Applications Meidanis (Unicamp) Network Science March 24, 2020 19 / 24

  20. Edge classification Depends on DFS itself, not just graph Types of edges: tree edges forward edges backward edges cross edges Meidanis (Unicamp) Network Science March 24, 2020 20 / 24

  21. Algorithm additions Starting and ending times useful to classify edges u forward edges: u → v with v u backward edges: u → v with v u cross edges: u → v with v impossible: Meidanis (Unicamp) Network Science March 24, 2020 21 / 24

  22. Undirected graph no forward edges no cross edges Meidanis (Unicamp) Network Science March 24, 2020 22 / 24

  23. Cycle detection Graph has a cycle ⇐ ⇒ DFS has a backward edge Meidanis (Unicamp) Network Science March 24, 2020 23 / 24

  24. Topological sorting Premises: Acyclic graphs Tasks that depend on one another Results: Topological sort: Safe order for the tasks DFS: reverse order of finishing times Meidanis (Unicamp) Network Science March 24, 2020 24 / 24

  25. Cycle detection DFS has a backward edge = ⇒ Graph has a cycle u backward edge: u → v with v a c b u starts while v active = ⇒ there is a path from v to u f e d g Meidanis (Unicamp) Network Science March 24, 2020 25 / 24

  26. Cycle detection Graph has a cycle = ⇒ DFS has a backward edge v k v 0 : first visited vertex in cycle v 0 v 1 , v 2 , v 3 , . . . , v k : start after v 0 v 1 , v 2 , v 3 , . . . , v k : start before v 0 finishes v 1 v 0 Therefore, v k v 2 and v k → v 0 is a backward edge v 3 Meidanis (Unicamp) Network Science March 24, 2020 26 / 24

  27. Topological sorting Example: getting dressed socks socks → shoes shoes underwear → trousers trousers shirt → trousers belt trousers → belt shirt trousers → shoes underwear socks shoes shirt underwear trousers belt Meidanis (Unicamp) Network Science March 24, 2020 27 / 24

  28. Topological sorting Example: getting dressed socks shoes shirt underwear trousers belt shoes, socks, belt, trousers, underwear, shirt ✛ belt, shoes, trousers, shirt, socks, underwear ✛ Meidanis (Unicamp) Network Science March 24, 2020 28 / 24

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend