Graphs-Part-II-Dorr-after-class

# Graphs-Part-II-Dorr-after-class - Given a graph one way to...

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

Given a graph, one way to visit every vertex in that graph is via a breadth- first search. Select a starting point. Visit all vertices that are “one jump” away from it. Visit all vertices that are “two jumps” away from it.

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

View Full Document
A simple problem that can be solved using this general technique is that of finding the shortest path between two vertices in an undirected and unweighted graph. If the graph is not connected, what happens?
Starting at vertex s V generate an array of distances from s called dist[] such that for all v V , dist[v]=length of shortest path from s to v. dist[s]=0 We will also create a predecessor array of the last vertex we were at before getting to the end of the path from s to v for all v V , pred[v]=“one step back” pred[s]=none With just these two arrays, we will be able to reconstruct any shortest part request from s to some vertex. This is because any

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.

{[ snackBarMessage ]}

### Page1 / 12

Graphs-Part-II-Dorr-after-class - Given a graph one way to...

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

View Full Document
Ask a homework question - tutors are online