الگوریتم کروسکال

از ویکی جامع پردیس دانشگاهی دانشگاه قم
پرش به: ناوبری، جستجو
voidkruskal(int n, int m,set_ of _ edges E, set _ of _edges &F )
{
   index i, j
   set_ pointer p , q
   edge e
   sort the m edges in E by weight in nondecreasing order
   F = Ø
   intitial(n)
   while(number of edges in F is less than n-1)
   {
      e= edge with least weight not yet considered
      i, j = indices of vertices connected by e
      p = find (i)
      q = find (j)
      if(!equal ( p, q ))
      {
         merge ( p , q )
         add e to F
      }
   }
}