Lowest cost edge where edge weights are between 0 and 1 - algorithm

I am given a graph G = (V, E). Each edge has probability of failure which is equal to its edge weight. Each edge weight is between 0 and 1. I need to find the path of the lowest probability of failure. This means a path where the total weight is 1 - ((1 - w(e1))(1 - w(e2))...).
To me, this doesn't seem like a shortest path problem because the shortest path may have the highest weights. I thought that a modified Dijkstra's algorithm would work where instead of checking if d[v] > d[u] + w(u, v) I would check if d[v] < d[u] + w(u, v) but that can't possibly be it. I am stuck. Can anyone offer advice?

Related

Design an algorithm for the single source shortest path problem that runs in time O(k(|V|+|E|))

Suppose we are given a directed graph G = (V, E) with potentially positive and negative edge lengths, but no negative cycles. Let s ∈ V be a given source
vertex. How to design an algorithm for the single-source shortest path problem that runs in time O(k(|V | + |E|)) if the shortest paths from s to any other vertex takes at most k edges?
Here`s O(k(|V | + |E|)) approach:
We can use Bellman-Ford algorithm with some modifications
Create array D[] to store shortest path from node s to some node u
initially D[s]=0, and all other D[i]=+oo (infinity)
Now after we iterate throught all edges k times and relax them, D[u] holds shortest path value from node s to u after <=k edges
Because any s-u shortest path is atmost k edges, we can end algorithm after k iterations over edges
Pseudocode:
for each vertex v in vertices:
D[v] := +oo
D[s] = 0
repeat k times:
for each edge (u, v) with weight w in edges:
if D[u] + w < D[v]:
D[v] = D[u] + w

Find the minimum weight cycle that contains a specific edge

given a graph:
- oriented,
- strongly connected and
- weighed (the weights are all positive)
I have to write a function that taken as input an edge (u, v), calculate the weight of the cycle of minimum weight that contains this edge.
I thought I'd do as follows but the procedure is inaccurate and incomplete:
- Starts a bfs visit starting from node u
- Keep in a variable the temporary weight
- When you arrive to v choose the minimum of the previous weights.
How do I keep track of previous weights? How to write the pseudocode?
I have no idea how to get started so someone help me?
Thanks
This can be reduced to Shortest Path Problem:
Find the shortest path from v to u, then the shortest cycle that contains (u,v), is v->...->u->v, where v->...->u is the shortest path from v to u as found by the shortest path algorithm.
It can be solved efficiently using Dijkstra's Algorithm, since there are no negative weights in the graph.
Correctness Proof:
Assume there is a cheaper cycle v1->v2->...vi->u->v->v_i+1->...->vn->v1. Let's say it weights x < d(v,u) + w(u,v)
Since it's a cycle, we can look at it as v->v_i+1->....->vn->v1->...->vi->u->v.
The weight of the cycle didn't change, and is still x. This means x=w(v,v_i+1) + ... + w(vn,v1) + ... + w(v_i-1,vi) + w(vi,u) + w(u,v)
But this gives us w(v,v_i+1) + ... + w(vn,v1) + ... + w(v_i-1,vi) + w(vi,u) + w(u,v) - w(u,v) < d(v,u), and we have found a shorter path from v to u, than d(v,u), which is contradicting correctness of Dijkstra's Algorithm.
QED

Number of lightest paths from single source vertex

Assume I have a directed, weighted graph with positive or negative weights, (with no zero or negative weighted loops).
The graph is Bellman-Ford analized, meaning each vertex holds the data of the lightest path to it from the source vertex, and its predecessor in the lightest path.
What is the most efficient way to store the number of different shortest paths from the source to each vertex?
I am willing to make it in linear time - O(V+E) if possible.
You can do it pretty efficiently if you have no negative edges as well.
Let the shortest path to node v be denoted as D(v)
sort vertices by distances - O(VlogV)
Denote P(v) - number of paths leading from the source to v.
Now, you can use DP to solve this relation (from first to last):
P(source) = 1
P(v) = sum { P(u) | (u,v) is an edge and D(u) + w(u,v) = D(v) }
Complexity of the algorithm is O(VlogV + E)
Correctness proof: by induction (guidelines):
Base clause for source, there is a single path (the empty path).
let us assume P(v) is correct for every v such that D(v) < D(u).
For every shortest path that ends with u, it must go through one of the vertices such that D(v) < D(u). Given a shortest path source->...->v->u, the path is counted in P(v). In addition, it is not counted for any other P(v'), so it is counted exactly once in sum { P(u) | (u,v) is an edge and D(u) + w(u,v) = D(v) }.
In addition, for any path which is not shortest path, from induction hypothesis, it is not counted for any v such that D(v)<D(u), so the path must be generated in the last step, but the restriction (u,v) is an edge and D(u) + w(u,v) = D(v) is preventing it, so we do not count any non-shortest path.
QED

dijikstras algorithm for a node with no path

How will the Dijkstra's algorithm work when the shortest path weight are infinity or - infinity( ie if there is no path or no shortest path)?
How will triangular inequality ( d[v] = d[u] + w[u,v]) ) be true?
I assume v is the target node, u is the parent (here there is no parent) and w is the weight of the edge(uv) which i think is zero.
If there is no parent to some node v, there is no u such that the edge (u,v) exists.
Therefore, the step d[v] = d[u] + w[u,v] will never take place, and the initial value of d[v] (which is set to infinity) will be unchanged until the algorithm halts.
In other words, the triangle inequality d[v] <= d[u] + w[u,v] is vacuous true for all the edges (u,v) in the graph.

Finding all shortest paths from source to all vertices in a digraph

We are given a directed graph G (possibly with cycles) with positive edge weights, and the minimum distance D[v] to every vertex v from a source s is also given (D is an array this way).
The problem is to find the array N[v] = number of paths of length D[v] from s to v,
in linear time.
Now this is a homework problem that I've been struggling with for quite long. I was working along the following thought : I'm trying to remove the cycles by suitably choosing an acyclic subgraph of G, and then try to find shortest paths from s to v in the subgraph.
But I cannot figure out explicitly what to do, so I'd appreciate any help, as in a qualitative idea on what to do.
You can use dynamic programming approach in here, and fill up the number of paths as you go, if D[u] + w(u,v) = D[v], something like:
N = [0,...,0]
N[s] = 1 //empty path
For each vertex v, in *ascending* order of `D[v]`:
for each edge (u,v) such that D[u] < D[v]:
if D[u] + w(u,v) = D[v]: //just found new shortest paths, using (u,v)!
N[v] += N[u]
Complexity is O(VlogV + E), assuming the graph is not sparsed, O(E) is dominanting.
Explanation:
If there is a shortest path v0->v1->...->v_(k-1)->v_k from v0 to v_k, then v0->...->v_(k-1) is a shortest path from v0 to v_k-1, thus - when iterating v_k - N[v_(k-1)] was already computed fully (remember, all edges have positive weights, and D[V_k-1] < D[v_k], and we are iterating by increasing value of D[v]).
Therefor, the path v0->...->v_(k-1) is counted in the number N[V_(k-1)] at this point.
Since v0->...->v_(k-1)-v_k is a shortest path - it means D[v_(k-1)] + w(v_k-1,v_k) = D[v_k] - thus the condition will hold, and we will add the count of this path to N[v_k].
Note that the proof for this algorithm will basically be induction that will follow the guidelines from this explanation more formally.

Resources