1 / 2

// Global arrays indexed by vertex number int[] dist // dist[u] = distance from s to u

// Global arrays indexed by vertex number int[] dist // dist[u] = distance from s to u int[] prev // prev[u] = u’s predecessor in BFS tree // Dijkstra’s alg. for G = (V,E), starting at vertex s. void dijkstra (G, s) for each u in V dist[u] =  prev[u] = null

danton
Download Presentation

// Global arrays indexed by vertex number int[] dist // dist[u] = distance from s to u

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. // Global arrays indexed by vertex number int[] dist // dist[u] = distance from s to u int[] prev // prev[u] = u’s predecessor in BFS tree // Dijkstra’s alg. for G = (V,E), starting at vertex s. void dijkstra (G, s) for each u in V dist[u] =  prev[u] = null dist[s] = 0 Q = new PriorityQueue(|V|) Q.decreaseKey(s, 0) while (!Q.isEmpty()) u = Q.deleteMin() for each edge (u,v,w) in E if (dist[v] > dist[u] + w) dist[v] = dist[u] + w prev[v] = u Q.decreaseKey(v, dist[v])

  2. // Global arrays indexed by vertex number int[] dist // dist[u] = distance from s to u int[] prev // prev[u] = u’s predecessor in SP tree // BFS of G = (V,E), starting at vertex s. void bfs (G, s) for each u in V dist[u] =  prev[u] = null dist[s] = 0 Q = new Queue() Q.enqueue(s) while (!Q.isEmpty()) u = Q.dequeue() for each edge (u,v) in E if (dist[v] = ) dist[v] = dist[u] + 1 prev[v] = u Q.enqueue(v)

More Related