CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.

16
CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    233
  • download

    0

Transcript of CSE 780 Algorithms Advanced Algorithms SSSP Dijkstra’s algorithm SSSP in DAGs.

CSE 780 Algorithms

Advanced Algorithms

SSSP Dijkstra’s algorithm

SSSP in DAGs

CSE 780 Algorithms

Review

Given edge (u,v) (s,v) ≤ (s,u) + w(u,v)

Relax(u,v,w)

If d[u] = (s,u) before the operation Then d[v] = (s,v)

Path relaxation property

CSE 780 Algorithms

Directed Acyclic Graphs

SSSPs in DAGs, allowing negative weights

Can be done in O(|V| + |E|)

CSE 780 Algorithms

Pseudo-code

Time complexity:O(|V| + |E|)

CSE 780 Algorithms

Example

CSE 780 Algorithms

Correctness

Claim: d[v] = (s, v) at termination Assume

is the shortest path Relax happens in order of path Therefore claim is true

by Path-Relaxation property

= v= s

CSE 780 Algorithms

Shortest-Paths Problem

A shortest-paths problem, given a weighted, directed graph G=(V,E) with weight function w: E→ R, is to find the shortest path between two arbitrary vertices, u and v.

This problem is a generalization of BFS to handle weighted graphs.

Edge weights can be interpreted, instead of as distances, as time, cost, etc.

CSE 780 Algorithms

Dijkstra’s Algorithm

Given directed graph G=(V,E), with only non-negative weights

Bear similarity to breadth-first search and Prim’s algorithm

Maintain a set S V whose shortest-path from source s have already been determined.

Use a min-priority queue Q to store V-S, keys are the shortest path weight estimate d[v]

Repeatedly select next vertex from V-S, and add it to S.

CSE 780 Algorithms

INIT-SINGLE-SOURCE(V,s)

For each vertex v ε V

do d[v] ←∞

л[v] ← NIL

d[s] ← 0

CSE 780 Algorithms

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

CSE 780 Algorithms

Pseudo-code

Only d[s] = 0in Q

If d[v] improves during the Relax operation, do Decrease-key(Q, v, d[v])

CSE 780 Algorithms

Example

CSE 780 Algorithms

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

CSE 780 Algorithms

Analysis

Time complexity: #Extract-min: O(|V|) #Decrease-key = #Relax: O(|E|) Use binary heap for priority heap:

Time complexity: O((|V| + |E|) log |V|) Use Fibonacci heap for priority heap:

Amortized time complexity: O(|V| log |V| + |E|)

Greedy algorithm: Any moment, select the lightest vertex in V-S to add to

set S

CSE 780 Algorithms

Correctness

Claim: At the start of each iteration of the while loop, d[v] =

(s, v) for each vertex v S. Proof: (by contradiction)

Let u be the first vertex d[u] (s,u) when added to S Must be a shortest path from s to u

CSE 780 Algorithms

Remarks

Similar to breadth-first search, It adds nodes into S in order of their distance to s

The algorithm also induces a shortest-paths tree

Why is non-negative weights required? Example?