Daa Unit 4 Prims
Daa Unit 4 Prims
GREEDY TECHNIQUE
On each step—and this is the central point of this
technique—the choice made must be:
The second way to prove optimality of a greedy algorithm is to show that on each step
it does at least as well as any other algorithm could in advancing toward the
problem’s goal.
The third way is simply to show that the final result obtained by a greedy algorithm is
optimal based on the algorithm’s output rather than the way it operates.
9.1 Prim’s Algorithm
On each iteration, the algorithm expands the current tree in the greedy
manner by simply attaching to it the nearest vertex not in that tree.
Vertices that are not adjacent to any of the tree vertices can be given
the ∞ label indicating their “infinite” distance to the tree vertices and
a null label for the name of the nearest tree vertex.
Alternatively, we can split the vertices that are not in the tree into
two sets, the “fringe” and the “unseen.”
With such labels, finding the next vertex to be added to the current
tree T = *VT , ET + becomes a simple task of finding a vertex with the
smallest distance label in the set V − VT .