Algorithm Analysis (CSC 301 2015F) : EBoards

CSC301.01 2015F, Class 29: Shortest Paths


Overview

Preliminaries

Admin

Extra Credit

Academic

Peer

Questions

Problem 6-1 is too much work. Fixed.

How do you do max-flow? Look it up in the book.

What is a data structure? An arrangement of memory.

The Shortest-Path Problem

Given a weighted graph and two designated vertices (start and finish; source and sink), find the shortest path from one vertex to the other.

Dijkstra's Shortest-Path Algorithm

Find the shortest distance from A to every other node!

Node predecessor[n] // Predecessor on shortest path
int distance[n]     // Distance to node; initialize to infinite
boolean processed[n]// Have we processed node n.

distance[source] = 0
while there are unprocessed nodes
  find u, the unprocessed node with the shortest distance
  mark u as processed
  for each edge (u,v)
    if (distance[u] + weight[u,v] < distance[v])
      predecessor[v] = u
      distance[v] = distance[u] + weight[u,v]

An Example

Analyzing Dijkstra's Shortest Path Algorithm

All Pairs Shortest Path Algorithms

I want the cost of the shortest path from each node to every other node.

I could run Dijkstra's algorithm with every point as the starting point.

Running time: O(((n^2)*(logn)) + nm)

Floyd-Warshall

An O(n^3) algorithm that is generally much faster than "Run Dijkstra's n times".

We will number the nodes from 0 to n-1. Build the shortest path from each node to every other other node that only use nodes 0 .. k as intermediate nodes. Example and further discussion next time.