This line if(mst[i]=false && key[i]<min) has an assignment = instead of a comparison ==. This will always cause the if test to always fail, so your min_index will never be set....

java,minimum-spanning-tree,prims-algorithm

The PriorityVertex from this example is just a class that the asker created. It is a simple implementation of a vertex in a graph. This class implements the Comparable interface. The reason for that is that PriorityQueue must compare its elements. This can be achieved in two ways: The elements...

In graph algorithms as in your question, if weights are given, usually adjacency is not explicitly encoded in addition to the weights. Instead, the graph is considered to be a complete graph (i.e. evey vertex is adjacent to any other vertex), but for non-adjacent vertices u, v in the initial...

java,priority-queue,prims-algorithm

A few things: The default implementation of PriorityQueue cannot re-order items within the queue dynamically. In other words, when you change the key after adding items in, it won't cause the items already in the queue to change their ordering. When you first add nodes into the PriorityQueue, they are...

algorithm,data-structures,prims-algorithm,treap

This will not necessarily make Prim's algorithm any faster. Consider the following degenerate case - you have n nodes v1, v2, ..., vn, and their priorities are such that p(v1) < p(v2) < p(v3) < ... < p(vn). In that case, the treap will be a degenerate linked list, and...

java,algorithm,minimum-spanning-tree,prims-algorithm

Prims algorithm uses the weight of the edge to determine the best path. Posting the vertex to the PriorityQueue will not work. I am guessing your Edge class will implement Comparable by comparing their lengths....

java,algorithm,heap,minimum-spanning-tree,prims-algorithm

Thanks friends for investing time to my question, but I figured that I had few mistakes in my implementation due to which I was getting wrong answer. I corrected the state of the vertex when it is added to the MinHeap I corrected the logic of outputting the edge of...