Shortest paths algorithms Flashcards
What is the generic algorithm for finding delta(s,v) for all v’s?
Init:
- d(s)=0, d(v)=infinity
loop:
-
while (exists an edge (u,v) for which d(v)>d(u)+w(u,v):
- find such an edge and call Relax(u,v,w)
end:
- return d(v) for every v
Lower bound claim
All along the run of the algorithm, for all v, the inequality: d(v)>=delta(s,v) is satisfied, and if d(v)
proof that claim.
Using induction on the number of Relax operations
-
base: after initilization
- v is not s, delta(s,v)
- d(s)=0 = delta(s,s)
-
Induction assumption
- by the end of the i-1 step, the assumption is satisfied.
-
step
- Let’s look at Relax on the ith step.
-
case 1: no update
- array d stays the same
-
case 2: updated
- d(v)-the only one that has changed.
- d(v)=d(u)+w(u,v)
- d(u)>=delta(s,u) (by I.A)
-
delta(s,u)+w(u,v) >= delta(s,v)
- observation.
- d(v)>= delta(s,u)+w(u,v)>=delta(s,v)
-
since d(v) is updated:
- d(v)
- d(u) - a weight of some Psu.
- d(v)=d(u)+w(u,v)*-**weight of Psu+(u,v)*
What is the correctness statement for the generic algorithm?
If through the run of the algorithm, for every edge (u,v), d(v)<=d(u)+w(u,v) is satisfied(that is, the algorith, stops), then, for every v, d(v)=delta(s,v).
What is the correctness statement proof for the generic algorithm, in case it stops?
-
Assume the algorithm stopped
- for all (u,v) in E, d(v)<=d(u)+w(u,v)
-
Assume in negation: there exists x in V s.t:
- d(x) != delta(s,x)
- Let Psx the lightest path from s to x.
-
let v be the first vertex in P s.t. d(v) != delta(s,v)
- by the lower bound claim: d(v)>delta(s,v)
-
let u be the preceding vertex to v in P
- d(u) = delta(s,u)
-
By sub-paths of a shortests path prinicipal
- delta(s,u)+w(u,v)=delta(s,v).
-
d(v)<=d(u)+w(u,v)=delta(s,u)+w(u,v)=delta(s,v)
- contradiction
What is the “full” correctness statement of the generic algorithm?
What is the exact definition of
rooted tree in vertex s
Directed graph is called rooted tree in vertex s if every vertex in the graph is accessible from s, and it is accessible only via one path
Which data structure can help us maintain a rooted tree in vertex s?
It can be maintaind via array of length |V|
- The index of a cell represents some vertex*
- The content of cell v is former(v)*
“lightest paths tree T for graph G and source s”
what is it?
It is a rooted tree in vertex s which satisfies:
for every v, the only path from s to v in T is the lightest path from s to v in G.
General algorithm, what claims are used in order to prove the correctness statement?
Generic algorithm, how the first claim is proved?
- N.T.F - d(u) = delta(s,u)
- lower bound claim - d(u)>=delta(s,u)
-
d(v)=d(u)+w(u,v) = delta(s,v)
- last Relax operation -> d(v)=delta(s,u)
- delta(s,v)<= delta(s,u)+w(u,v)
-
d(u)+w(u,v) = delta(s,v)<=delta(s,u)+w(u,v)
- d(u)<=delta(s,u)
-
d(u)>=delta(s,u) & d(u)<=delta(s,u)
- d(u) = delta(s,u)
General algorithm, proof for the 2nd claim.
What is the induction based on
It is based on the size of V’. That is, |V’|.
Genereal algorithm, proof of the 2nd claim.
What is the base case for the induction proof?
- |V’| = 1.*
That is:
- V’ = {s}
- E’ = empty set.
Trivial.
- Generic algorithm, proof of the 2nd claim.*
- what is the step in the induction?*
- we look at the next vertex v to be added into V’. That is, the next vertex for which d(v) = delta(s,v).*
- N.T.S: T=(V’ U {v}, E’ U {former(v),v})* is a shortest paths tree.
Generic algorithm, proof of the 2nd claim.
What is the proof for the step phase of the induction?
According to the 1st claim: d(v)=delta(s,v) means:
- former(v) = delta(s,former(v))
- therefore, former(v) is in V’ too.
Proof: T is a tree.
- (V’,E’) is a tree.
- former(v) is in V’
- we added an edge from former(v) to a new vertex v in V’.
proof: T is a shortest paths tree from s
- I.A holds for all other vertices. N.T.F for v.
-
The path Psv in T is composed of:
- Psformer(v) + (former(v),v)
- by the assumption: d(v)=delta(s,v)
- by claim 1: d(former(v)) = delta(s,former(v))
- w(Psv)=w(Psformer(v))+w(former(v),v) =
- delta(s,former(v))+w(fomer(v),v)=d(v) = delta(s,v)
Generic algorithm, what is the proof for the correctness statement, using the claims.
- If the algorithm stops, then we proved that for all v, d(v) = delta(s,v) is satisfied.*
- Therefore, the Tree V’=V E’={(former(v),v): v!=s} can be created, and by the 2nd claim - G = (V’,E’) is a lightests paths tree from s in G.*.
Dijstra, which graphs can it handle?
Directed or undirected graphs with non-negative weights.
Dijstra, which problem can it solve?
Finding the shortest paths from source s to all vertices.
_Dijstra, write exactly the Relax(u,v,w(u,v)) procedure_
Dijstra, show me the initilization step.
You are given G=(V,E),s,w
Dijstra, what is the loop step in the algorithm?
How is Dijkstra’s algorithm implemented?
what’s his run-time? divide it to operation on Q and operations on the array d
- Q is maintained by a minimum heap in which d(v) is a key.*
- we push mininum d(v) from Q using ExtractMin.*
- Q*
- Initilization of Q - O(|V|)
- There are exactly |V| Extract-Min operations.
- There are at most |E| Relax operations, which decreases the value of d(v). This implies O(|E|) decrease-key(v) operations (log(|V|)). In total - O(|E|log|V|).
- d
- Initializing d and s - O(|V|)
- |E| Relax operations on d(v), each O(1). O(|E|)
- In total: O(|E|+|V|).
In total: O(|E| log|V|)
Dijkstra, what is the lower bound claim?
d(v)>=delta(s,v)
That is, d(v) is always greater equal to the value of the lightest path.
Dijkstra, What is the correctness statement?
When the algorithm is done, for all v, d(v)=delta(s,v)
- Dijkstra, which observation is used in the proof?*
- Explain it.*
Once vertex u is being added to S, d(u) does not change.
Explanation:
- After u is being added to S, we execute Relax operation on vertex v from U, which share an edge with u. The updated value is d(v), and is again, is not chosen from S.
Dijkstra, what is the first claim?
Claim 1:
- After Relax(u,v), d(v)<= d(u)+w(u,v) is satisfied through all the remaining steps of the algorithm.
Diskjstra, what is the proof for the first claim?
By the end of Relax(u,v):
- d(v)=min{d(v),d(u)+w(u),v} is satisfied.
- That is, d(v)<= d(u)+w(u,v)
- Relax is performed due to the insertion of u into S.
- According to the observation: d(u) will not further change.
- In contrast, d(v) might change, but only decrease, so the inequality holds.
Dijkstra, what is the helping statement?
When vertex u is being added to S d(u)=delta(s,u) is satisfied.
That is, d(u) holds the value for the lightest path
Dijkstra, what is the proof for the correctness statement?
Proof of the correctness statement
-
In each step a vertex shifts from Q to S
- After |V| iterations, S=V and the algorithm stops.
- By the helping statement, when vertex u enters S:
- d(u) = delta(s,u)
- By the observation, this value does not change.