Question

For Dijkstra’s shortest path algorithm: a. Give the Big-O time for Dijkstra’s shortest path algorithm and...

For Dijkstra’s shortest path algorithm:

a. Give the Big-O time for Dijkstra’s shortest path algorithm and explain your answer.

b. Does the answer to (a) depend on whether we use an adjacency matrix or list? Explain your answer.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a) In the below algorithm V=total no. of vertices. and E= total no. of edges

Simple algorithm is given below with Time complexity of O(V^2).

SP-Dijkstra()

n=number of nodes in the graph

for i=1 to n

cost[vi]= w(v1,vi);

S ={v1};

for j=2 to n {

find the smallest cost[vi]s.t.vi is not in s;

include vi to S;

for(all nodes vj not in S){

if (cost[vj] > cost [vi] +w(vi,vj))

cost[vj] =cost[vi]+w(vi,vj);

}

}

EXAMPLE:

The complexity of Dijkstra's shortest path algorithm is:

    O(|E| |decrease-key(Q)| + |V| |extract-min(Q)|)

where Q is the min-priority queue ordering vertices by their current distance estimate.

For both a Fibonacci heap and a binary heap, the complexity of the extract-min operation on this queue is O(log |V|). This explains the common |V| log |V| part in the sum. For a queue implemented with an unsorted array, the extract-min operation would have a complexity of O(|V|)(the whole queue has to be traversed) and this part of the sum would be O(|V|^2).

(the one with the edge factor |E|), the O(1) v.s. O(log |V|)difference comes precisely from using respectively a Fibonacci heap as opposed to a binary heap. The decrease key operation which may happen for every edge has exactly this complexity. So the remaining part of the sum eventually has complexity O(|E|) for a Fibonacci heap and O(|E| log |V|) for a binary heap. For a queue implemented with an unsorted array, the decrease-key operation would have a constant-time complexity (the queue directly stores the keys indexed by the vertices) and this part of the sum would thus be O(|E|), which is also O(|V|^2).

b)The time complexity for the matrix representation is O(V^2). In this post, O(ELogV) algorithm for adjacency list representation is discussed.

In Dijkstra’s algorithm, two sets are maintained, one set contains list of vertices already included in SPT (Shortest Path Tree), other set contains vertices not yet included. With adjacency list representation, all vertices of a graph can be traversed in O(V+E) time using BFS. The idea is to traverse all vertices of graph using BFS and use a Min Heap to store the vertices not yet included in SPT (or the vertices for which shortest distance is not finalized yet). Min Heap is used as a priority queue to get the minimum distance vertex from set of not yet included vertices. Time complexity of operations like extract-min and decrease-key value is O(LogV) for Min Heap.

Following are the detailed steps.
1) Create a Min Heap of size V where V is the number of vertices in the given graph. Every node of min heap contains vertex number and distance value of the vertex.
2) Initialize Min Heap with source vertex as root (the distance value assigned to source vertex is 0). The distance value assigned to all other vertices is INF (infinite).
3) While Min Heap is not empty, follow the below steps
a) Extract the vertex with minimum distance value node from Min Heap. Let the extracted vertex be u.
b) For every adjacent vertex v of u, check if v is in Min Heap. If v is in Min Heap and distance value is more than weight of u-v plus distance value of u, then update the distance value of v

Add a comment
Know the answer?
Add Answer to:
For Dijkstra’s shortest path algorithm: a. Give the Big-O time for Dijkstra’s shortest path algorithm and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT