1 / 39

Alyce Brady CS 510: Computer Algorithms

Depth-First Graph Traversal Algorithm. Alyce Brady CS 510: Computer Algorithms. Search: Look for a given node stop when node found, even if not all nodes were visited Traversal: Always visit all nodes. Search vs Traversal. Similar to Depth-first Traversal of a Binary Tree

lavey
Download Presentation

Alyce Brady CS 510: Computer Algorithms

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. Depth-First Graph Traversal Algorithm Alyce Brady CS 510: Computer Algorithms

  2. Search: Look for a given node stop when node found, even if not all nodes were visited Traversal: Always visit all nodes Search vs Traversal

  3. Similar to Depth-first Traversal of a Binary Tree Choose a starting vertex Do a depth-first search on each adjacent vertex Depth-first Search

  4. depth-first-search mark vertex as visited for each adjacent vertex if unvisited do a depth-first search on adjacent vertex Pseudo-Code forDepth-First Search

  5. Depth-First Search A B C D E F G

  6. Depth-First Search v A B C D E F G A

  7. Depth-First Search v A B C D E F G A

  8. Depth-First Search v A v B C D E F G A B

  9. Depth-First Search v A v B C D E F G A B

  10. Depth-First Search v A v B C D E F G A B

  11. Depth-First Search v A v B C v D E F G A B D

  12. Depth-First Search v A v B C v D E F G A B D

  13. Depth-First Search v A v B C v D E F G A B D

  14. Depth-First Search v A v B C v v D E F G A B D E

  15. Depth-First Search v A v B C v v D E F G A B D E

  16. Depth-First Search v A v B C v v D E F G A B D E

  17. Depth-First Search v A v B C v D E F G A B D E

  18. Depth-First Search v A v B C v v D E F G A B D E

  19. Depth-First Search v A v B C v v D E F G A B D E

  20. Depth-First Search v A v B C v v D E F G A B D E

  21. Depth-First Search v A v B C v v D E F G v A B D E F

  22. Depth-First Search v A v B C v v D E F G v A B D E F

  23. Depth-First Search v A v B C v v D E F G v A B D E F

  24. Depth-First Search v A v v B C v v D E F G v A B D E F C

  25. Depth-First Search v A v v B C v v D E F G v A B D E F C

  26. Depth-First Search v A v v B C v v D E F G v A B D E F C

  27. Depth-First Search v A v v B C v v D E F G v A B D E F C

  28. Depth-First Search v A v v B C v v v D E F G v A B D E F C G

  29. Depth-First Search v A v v B C v v v D E F G v A B D E F C G

  30. Depth-First Search v A v v B C v v v D E F G v A B D E F C G

  31. Depth-First Search v A v v B C v v v D E F G v A B D E F C G

  32. Depth-First Search v A v v B C v v v D E F G v A B D E F C G

  33. Depth-First Search v A v v B C v v v D E F G v A B D E F C G

  34. Depth-First Search v A v v B C v v v D E F G v A B D E F C G

  35. Depth-First Search v A v v B C v v v D E F G v A B D E F C G

  36. Depth-First Search A B C D E F G A B D E F C G

  37. Was this a true search? How would we make it a true search? Was this a true traversal? How would we make it a true traversal?

  38. Time Complexity Adjacency Lists Each node is marked visited once Each node is checked for each incoming edge O (v + e) Adjacency Matrix Have to check all entries in matrix: O(n2) Time and Space Complexityfor Depth-First Search

  39. Space Complexity Stack to handle nodes as they are explored Worst case: all nodes put on stack (if graph is linear) O(n) Time and Space Complexityfor Depth-First Search

More Related