{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2010 goodrich tamassia depth first search 9 example

Info icon This preview shows pages 9–14. Sign up to view the full content.

View Full Document Right Arrow Icon
©  2010 Goodrich, Tamassia Depth-First Search 9 Example (cont.) D B A C E D B A C E D B A C E D B A C E
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
©  2010 Goodrich, Tamassia Depth-First Search 10 DFS and Maze Traversal  The DFS algorithm is  similar to a classic  strategy for exploring  a maze We mark each  intersection, corner  and dead end (vertex)  visited We mark each corridor  (edge ) traversed We keep track of the  path back to the  entrance (start vertex)  by means of a rope  (recursion stack)
Image of page 10
©  2010 Goodrich, Tamassia Depth-First Search 11 Properties of DFS Property 1 DFS ( G, v ) visits all the  vertices and edges in  the connected  component of  v Property 2 The discovery edges  labeled by  DFS ( G, v ) form a spanning tree of  the connected  component of  v D B A C E
Image of page 11

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
©  2010 Goodrich, Tamassia Depth-First Search 12 Analysis of DFS Setting/getting a vertex/edge label takes  O (1)  time Each vertex is labeled twice  once as UNEXPLORED once as  VISITED Each edge is labeled twice once as UNEXPLORED once as  DISCOVERY  or  BACK Method incidentEdges is called once for each vertex DFS runs in  O ( n + m )  time provided the graph is  represented by the adjacency list structure Recall that  Σ v deg( v ) = 2 m
Image of page 12
©  2010 Goodrich, Tamassia Depth-First Search 13 Path Finding We can specialize the  DFS algorithm to find a  path between two given  vertices  u  and  z  using the  template method pattern We call  DFS ( G, u ) with  u   as the start vertex We use a stack  S
Image of page 13

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern