Algorithm Analysis (CSC 301 2015F) : EBoards

CSC301.01 2015F, Class 03: Reflective Activities


Overview

Preliminaries

Admin

Upcoming Work

Extra Credit

Academic

Peer

Questions

Dijkstra's Shortest-Path Algorithm

Slightly modified version of the version from Wikipedia, available at https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm.

 1  function Dijkstra(Graph, source, target):
 2
 3    dist[source] = 0              // Distance from source to source
 4    prev[source] = undefined      // Previous node in optimal path initialization
 5
 6    create vertex set Q           // Unvisited nodes
 7
 8    for each vertex v in Graph:   // Initialization
 9      if v != source:             // (unvisited nodes)
10        dist[v] = INFINITY        // Unknown distance from source to v
11        prev[v] = UNDEFINED       // Previous node in optimal path from source
12      add v to Q                  // All nodes initially in Q (unvisited nodes)
13      
14    while Q is not empty:
15      u = vertex in Q with min dist[u]    // Source node in the first case
16      remove u from Q 
17          
18      for each neighbor v of u:   // where v is still in Q.
19        alt = dist[u] + length(u, v) // length of path through u
20        if alt < dist[v]:         // A shorter path to v has been found
21          dist[v] = alt 
22          prev[v] = u 
23
24    return dist[target]           // or the path using prev

What's the running time? You can use n for the number of nodes and m for the total number of edges.

Morals

What's the underlying design principle?

Algorithm design principles

Questions for the class

Greedy algorithms

Quick review of asymptotic analysis

Additional characteristics of Big-Oh