graph_traversals_dijkstra

# graph_traversals_dijkstra - Graph Traversals Given a graph...

This preview shows pages 1–6. Sign up to view the full content.

Intro to Data Structures and Algorithms © BFS , Slide 1 Graph Traversals Given: a graph G a source vertex s in V[G] Goal: visit all the vertices of G to determine some property: Is G connected? Does G have a cycle? is there a v u path in G ? What is the shortest path? Will G disconnect if we remove a single edge? A vertex? G is the WWW - follow links to retrieve information .

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

View Full Document
Intro to Data Structures and Algorithms © BFS , Slide 2 Breadth First Search BFS(G,s) 1 Unmark all vertices 2 Enqueue(Q,s) 3 BFS-Tree ← φ 4 while Q ≠ φ 5 v Dequeue(Q) 6 visit(v) 7 for every w in Adj[v] 8 if w not yet visited 9 Enqueue(Q,w) 10 BFS-Tree BFS-Tree (v,w) visit(v) mark v
Intro to Data Structures and Algorithms © BFS , Slide 3 Example s 0 Q r s v w t u x y 0 ∞∞ r 1 s w t x 1 0 s w t x 1 2 0 u Q w 1 r 1 v y r 12 u Q r 1 t 2 x 2 v y

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

View Full Document
Intro to Data Structures and Algorithms © BFS , Slide 4 s w t x 1 2 0 s w t x 1 2 0 r 12 u t 2 Q x 2 v 2 v 2 y r v 2 u 3 x 2 Q v 2 u 3 y r s w t x 1 2 0 v 2 u 3 v 2 Q u 2 y 3 y 3
Intro to Data Structures and Algorithms © BFS , Slide 5 r 12 s w t x 1 2 0 u 3 Q y

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/08/2010 for the course ENGINEERIN 50-22-43-2 taught by Professor Prizler during the Spring '10 term at Tel Aviv Uni..

### Page1 / 19

graph_traversals_dijkstra - Graph Traversals Given a graph...

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

View Full Document
Ask a homework question - tutors are online