Posted by: atri | October 30, 2009

Lect 23: Shortest Path Problem (post # 2)

(Guest post by John Barker)

We began the class by quickly going over the proof we did the previous lecture regarding the greedy algorithm for the scheduling problem and proving that it outputs the optimal solution.

Atri also quickly showed us how to do the same proof by induction. [To be more precise, I mentioned that the claim that if there is an inversion then there is also a "consecutive" inversion, which we proved last lecture can also be done by induction. --Atri]

The max lateness of  \mathcal{O}^{\prime} < the max lateness of \mathcal O

  1. All the jobs before i and j have the same lateness.
  2. All the jobs after i and j also have the same lateness.
  3. The lateness of j in \mathcal{O}^{\prime} \le the lateness of j in \mathcal O.
  4. The lateness of i in \mathcal{O}^{\prime} \le the lateness of j in \mathcal O. (The lateness of i in \mathcal{O}^{\prime} = t - d_i < t - d_j = the lateness of j in \mathcal O.)

We then began to look at the shortest path problem.

Shortest Path Problem

  • Input:    A directed graph G = (V, E). For all e that exist in E, \ell_e \ge 0 and s, a start vertex exists in V.
  • Output: Shortest path P_u for all u \in V from s
    Def: \ell(P) = \sum_{e\in P} \ell_e.
    d(u) = minimum \ell(P) over all P connecting s to u
    For all u \in V, output P_u such that \ell(P_u) = d(u)

The graph is directed, all edges have a length greater than 0, and there is a start vertex in V. Note that to have an undirected graph is trivial because any undirected graph can be turned into a directed one, ie. an edge in an undirected graph can become two directed edges connecting each vertex to the other. The algorithm should output the shortest path from s to u with d(u) denoting the minimum path and \ell(P) being the value we are interested in comparing to d(u)

Our first guess was to look at a naive algorithm that is not at all efficient but would accomplish what we want. The naive algorithm would have to find all possible paths for all possible combinations, which is n!. Each path found would require O(n) (to verify if the path is the shortest path seen so far for the vertices) so altogether the naive algorithm would take O(n n!) time.

We then looked at algorithms we were already familiar with that might do the job and we decided the BFS would do the trick. Note that this algorithm will only work given that the graph’s edges have equal weight. The layer L_j of the BFS, has vertices that  end up being the distance j from the root that we are interested in.

We then studied an algorithm due to Edsger Dijkstra (developed in 1959) who won the Turing Award for his contributions. The Turing Award is given to those who make significant contributions to Computer Science.

In Dijkstra’s algorithm, you start with vertex s and maintain a set of ‘explored’ vertices S. For v\not\in S, define d'(v) = \min_{e = (u,v), u \in s} d(u) + \ell_e.

You have  shortest paths in S that you maintain and build greedily, at each v adding the length of edge (u, v) to the shortest path d(u).

The algorithm (which can be found in the book)

  1. S = \{s\}, d(s) = 0.
  2. While there exists a v \not \in S, such that (u, v) \in E with u \in S
    • pick w that minimizes d'(w) = \min_{e = (u, w) \in E, u \in S}d(u) + \ell_e
    • add w to S (and set d(w)=d'(w)–Atri).

Atri then showed a quick example of how the Dijkstra’s algorithm works.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.

Join 75 other followers