python implementation code fragment presents python implementation of the prim-jarnik algorithm the mst is returned as an unordered list of edges def mst primjarnik( ) """compute minimum spanning tree of weighted graph return list of edges that comprise the mst (in arbitrary order "" ={ [vis bound on distance to tree tree list of edges in spanning tree pq adaptableheappriorityqueued[vmaps to value (ve=( , ) pqlocator map from vertex to its pq locator for each vertex of the graphadd an entry to the priority queuewith the source having distance and all others having infinite distance for in vertices) if len( = this is the first node [ make it the root elsepositive infinity [vfloatinf pqlocator[vpq add( [ ]( ,none) while not pq is empty) key,value pq remove min ,edge value unpack tuple from pq del pqlocator[uu is no longer in pq if edge is not none tree append(edgeadd edge to tree for link in incident edges( ) link opposite( if in pqlocatorthus not yet in tree see if edge ( ,vbetter connects to the growing tree wgt link element if wgt [ ]better edge to [vwgt update the distance pq update(pqlocator[ ] [ ](vlink)update the pq entry return tree code fragment python implementation of the prim-jarnik algorithm for the minimum spanning tree problem