notes40

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

Info iconThis 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/02/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 3

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online