Docsity

DFS and Minimum Spanning Tree, Slides of Computer Science

Partial preview of the text

Download DFS and Minimum Spanning Tree and more Slides Computer Science in PDF only on Docsity!

Algorithms

Topological Sort

Minimum Spanning Trees

Review: Breadth-First Search

BFS(G, s) { initialize vertices; Q = {s}; // Q is a queue (duh); initialize to s while (Q not empty) { u = RemoveTop(Q); for each v ∈ u->adj { if (v->color == WHITE) v->color = GREY; v->d = u->d + 1; v->p = u; Enqueue(Q, v); } u->color = BLACK; } } v->p represents parent in tree v->d represents depth in tree

source vertex

source vertex d f

source vertex d f

source vertex d f

source vertex d f

source vertex d f

source vertex d f

source vertex d f

source vertex d f

source vertex d f

source vertex d f

source vertex d f