1,820 views
2 votes
2 votes
Suppose that all edge weights in a graph are integers in the range from 1 to |V|. How fast can you make Prim's algorithm run? What if the edge weights are integers in the range from 1 to W for some constant W?

Answer given :-

The running time of Prims algorithm is composed of :

• O(V) initialization.

• O(V · time for EXTRACT-MIN).

• O(E · time for DECREASE-KEY).

If the edges are in the range 1, . . . , |V| the Van Emde Boas priority queue can speed up EXTRACT- MIN and DECREASE-KEY to O(lg lg V) thus yielding a total running time of O(V lg lg V +E lg lg V) = O(E lg lg V ). If the edges are in the range from 1 to W we can implement the queue as an array [1...W+1] where the ith slot holds a doubly linked list of the edges with weight i. The (W+1)st slot contains ∞. EXTRACT-MIN now runs in O(W) = O(1) time since we can simply scan for the first nonempty slot and return the first element of that list. DECREASE-KEY runs in O(1) time as well since it can be implemented by moving an element from one slot to another.

Doubt 1 : Incase of range 1, . . . , |V| , how EXTRACT- MIN and DECREASE-KEY speed up to O(lg lg V).

Doubt 2 : why doubly linked list is used for range 1.... |W| ??

1 Answer

Best answer
3 votes
3 votes

for clarification of your 1st doubt, you can read https://en.wikipedia.org/wiki/Van_Emde_Boas_tree

 

for 2nd doubt, i hope there is no need to use doubly linked list

 array [1...W+1]  ===> already array is sorted by edge weights

where ith slot holds a doubly linked list of the edges with weight i. 

let assume there are 5 edges with weight 15,

they use double linked list due to efficiently usage, if you use single linked list, after extracting one edge from it, you need to update it's previous node, next pointer. ( but no problem with using singly linked list )
 

but when you decrease the key, let the 3rd edge in weight 15,....

it need to update 2nd edge next pointer, array element points to new edge ( but no problem with using singly linked list )

 

 

selected by

Related questions

3 votes
3 votes
1 answer
1
Pooja Palod asked Oct 15, 2015
2,990 views
Suppose that edge weights are uniformly distributed over half open interval $[0,1)$. Which algorithm kruskal's or prim's can make you run faster?
1 votes
1 votes
0 answers
2
srestha asked Aug 24, 2018
965 views
For a sparse graph $G=(V,E)$ where $|E|=\Theta (V)$ is the implementation of Prim’s algorithm with a Fibonacci heap asymptotically faster than the binary-heap implement...