1 / 47

Lecture 32: Graph TRAVERSALS

CSC 213 – Large Scale Programming. Lecture 32: Graph TRAVERSALS. Today’s Goals. Make Britney sad through my color choices Revisit issue of graph terminology and usage Subgraphs , spanning, & connected graphs, oh my! Problems solved or why you should care about these

yuval
Download Presentation

Lecture 32: Graph TRAVERSALS

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. CSC 213 – Large Scale Programming Lecture 32:Graph TRAVERSALS

  2. Today’s Goals • Make Britney sad through my color choices • Revisit issue of graph terminology and usage • Subgraphs, spanning, & connected graphs, oh my! • Problems solved orwhy you should care about these • Just rats in a maze: using graphs to find the exit • Confident in your decisions: how to travel depth-first • Using bread-first searching to cover all the bases • 2 algorithms both alike in dignity: how do they differ?

  3. Today’s Goals • Make Britney sad through my color choices • Revisit issue of graph terminology and usage • Subgraphs, spanning, & connected graphs, oh my! • Problems solved orwhy you should care about these • Just rats in a maze: using graphs to find the exit • Confident in your decisions: how to travel depth-first • Using bread-first searchingto cover all the bases • 2 algorithms both alike in dignity: how do they differ?

  4. Graphs Solve Many Problems

  5. Subgraphs • Subgraphof G contains edges & vertices from G Graph

  6. Subgraphs • Subgraphof G contains edges & vertices from G Subgraph

  7. Subgraphs • Subgraphof G contains edges & vertices from G • Spanning subgraphis subgraphcontaining all vertices in G Subgraph Graph

  8. Subgraphs • Subgraphof G contains edges & vertices from G • Spanning subgraphis subgraphcontaining all vertices in G Subgraph Spanning subgraph

  9. Connected Graphs & Subgraphs • Connectedif path exists between all vertex pairs • Requires path, not edge, between vertices Connected Graph

  10. Connected Graphs & Subgraphs • Connectedif path exists between all vertex pairs • Requires path,not edge, between vertices Disconnected Graph

  11. Connected Graphs & Subgraphs • Connected if path exists between all vertex pairs • Requires path,not edge, between vertices • Connected component is subgraph containing all connected vertices • Often called “maximally connected” Disconnected Graph Graph

  12. Connected Graphs & Subgraphs • Connectedif path exists between all vertex pairs • Requires path,not edge, between vertices • Connected component is subgraph containing all connected vertices • Often called “maximally connected” Disconnected Graph Graph with 2 connected components

  13. Connected Graphs & Subgraphs • Connected if path exists between all vertex pairs • Requires path,not edge, between vertices • Connected component is subgraph containing all connected vertices • Often called “maximally connected” Disconnected Graph Graph with 2 connected components

  14. Tree • Connected acyclic graph • Resembles Tree structure Graph

  15. Tree • Connected acyclic graph • Resembles Tree structure Tree

  16. Tree • Connected acyclic graph • Resembles Tree structure • Don’t lose forest for trees • Forestis graph with multiple trees Tree Graph

  17. Tree • Connected acyclic graph • Resembles Tree structure • Don’t lose forest for trees • Forest is graph with multiple trees Tree Tree

  18. Tree • Connected acyclic graph • Resembles Tree structure • Don’t lose forest for trees • Forest is graph with multiple trees Tree Forest

  19. Spanning Tree • Subgraphthat is both spanning subgraph& tree • Contains all vertices in graph spanning subgraph • Tree  connected without any cycles Graph

  20. Spanning Tree • Subgraphthat is both spanning subgraph& tree • Contains all vertices in graph spanning subgraph • Tree  connected without any cycles Tree

  21. Spanning Tree • Subgraphthat is both spanning subgraph& tree • Contains all vertices in graph spanning subgraph • Tree  connected without any cycles Spanning subgraph

  22. Spanning Tree • Subgraphthat is both spanning subgraph& tree • Contains all vertices in graph spanning subgraph • Tree  connected without any cycles Spanning tree

  23. Spanning Tree • Subgraphthat is both spanning subgraph& tree • Contains all vertices in graph spanning subgraph • Tree  connected without any cycles Tree Than Spans Royals?

  24. Depth- & Breadth-First Search • Common graph traversal algorithms • DFS & BFS traversals have common traits • Visits all vertices and edges in G • Determines whether of not Gis connected • Finds connected components if G not connected • Heavily used to solve graph problems

  25. DFS and Maze Traversal • Classic maze strategy • Intersection, corner, & dead endare vertices • Corridors become edges • Traveled corridors marked • Marks trace back to start

  26. DFS Example unexplored vertex A visited vertex A unexplored edge A discovery edge back edge B D E C

  27. DFS Example unexplored vertex A visited vertex A unexplored edge A discovery edge back edge B D E C

  28. DFS Example unexplored vertex A visited vertex A unexplored edge A discovery edge back edge ??? B D E C

  29. DFS Example unexplored vertex A visited vertex A unexplored edge A discovery edge back edge B D E C

  30. DFS Example unexplored vertex A visited vertex A unexplored edge A discovery edge back edge B D E C

  31. DFS Example unexplored vertex A visited vertex A unexplored edge A discovery edge back edge B D E C

  32. DFS Example unexplored vertex A visited vertex A unexplored edge A discovery edge back edge B D E C

  33. Properties of DFS • Connected component’svertices & edges visited • Edges visited form spanning tree for component A B D E C

  34. Properties of DFS • Connected component’svertices & edges visited • Edges visited form spanning tree for component A B D E C

  35. BFS Example unexplored vertex A visited vertex A unexplored edge L0 A discovery edge cross edge B D E C F

  36. BFS Example unexplored vertex A visited vertex A unexplored edge L0 A discovery edge cross edge L1 B D E C F

  37. BFS Example unexplored vertex A visited vertex A unexplored edge L0 A discovery edge cross edge L1 B D E C F

  38. BFS Example unexplored vertex A visited vertex A unexplored edge L0 A discovery edge cross edge L1 B D E C F

  39. BFS Example unexplored vertex A visited vertex A unexplored edge L0 A discovery edge cross edge L1 B D E C F

  40. BFS Example unexplored vertex A visited vertex A unexplored edge L0 A discovery edge cross edge L1 B D E L2 C F

  41. BFS Example unexplored vertex A visited vertex A unexplored edge L0 A discovery edge cross edge L1 B D E L2 C F

  42. BFS Example unexplored vertex A visited vertex A unexplored edge L0 A discovery edge cross edge L1 B D E L2 C F

  43. BFS Example unexplored vertex A visited vertex A unexplored edge L0 A discovery edge cross edge L1 B D E L2 C F

  44. BFS Example unexplored vertex A visited vertex A unexplored edge L0 A discovery edge cross edge L1 B D E L2 C F

  45. Properties of BFS • Some properties similar to DFS: • Visits all vertices & edgesin connected component • Component’s spanning tree from discovery edges • For each vertex v in Li • Spanning treehas exactlyi edgeson path from s to v • All paths in G from s to v have at least iedges L0 A L1 B D E L2 C C F

  46. DFS vs. BFS DFS BFS Back edge (v,w) • w is ancestor of vin tree of discovery edges Cross edge (v,w) • v in same or previous level as win tree of discovery edges A L0 A B D E L1 B D E L2 C C F C

  47. For Next Lecture • Weekly assignment available & due Tuesday • Gives you good chance to check your understanding • Next Fri. 1st check-in for program assignment #3 • Planning now saves time later! • Read 13.4.1 – 13.4.3 for class on Monday • When using directed edges, what changes needed? • Other computations possible for directed graphs?

More Related