notes40 - Jason D Ortiz Week 14 Notes CS251 Gustavo Depth...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Jason D. Ortiz Week 14 Notes CS251 – Gustavo Depth First Search Assume the following graph: B E A D G C F DFS – visit the children before the siblings - Assign sequence num at the time of visit - Label the edges as back edge or discovery edge - Start at A A-1, B-2, (a->b = discovery), C-3, (b->c = discovery), (c->a = back),D-4,(c- >d = discovery),(d->b = back), E-5,(d->e = discovery),F-6,(e->f = discovery), (f->d = back),G-7,(f->g = discovery),(g->e = discovery) Algorithm (DFS) For each edge incident in the graph, do If edge is unexplored If vertex is unexplored Label edge as discovery Visit vertex Call DFS recursively Else Label as back edge **We can eliminate the recursion of DFS by using a stack Implementation(DFS) Void DFS(int n, int **am, int **seq, int ***disc, int ***back){ //input //n is the number of vertices //am is adjacency matrix as an array of pointers to rows //output //seq stores an array of seq numbers of the vertices visited //disc is a pointer to an array with the discovery edges //back is a pointer to an array with the back edges *seq = new int[n]; int *pseq = *seq;
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
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