<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>Comments on: Computer Algorithms: Kruskal&#8217;s Minimum Spanning Tree</title>
	<atom:link href="/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/feed/" rel="self" type="application/rss+xml" />
	<link>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/</link>
	<description>on web development</description>
	<lastBuildDate>Fri, 26 Oct 2018 21:40:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>By: Akshay Wagh</title>
		<link>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/comment-page-1/#comment-448518</link>
		<dc:creator><![CDATA[Akshay Wagh]]></dc:creator>
		<pubDate>Fri, 07 Apr 2017 14:15:31 +0000</pubDate>
		<guid isPermaLink="false">/?p=3439#comment-448518</guid>
		<description><![CDATA[I don&#039;t want implementation,just give me an algorithm.]]></description>
		<content:encoded><![CDATA[<p>I don&#8217;t want implementation,just give me an algorithm.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Victor</title>
		<link>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/comment-page-1/#comment-443466</link>
		<dc:creator><![CDATA[Victor]]></dc:creator>
		<pubDate>Tue, 28 Feb 2017 07:37:00 +0000</pubDate>
		<guid isPermaLink="false">/?p=3439#comment-443466</guid>
		<description><![CDATA[Just managed to implement it after almost four years. Took some time, but I managed to do it in O(N^2).]]></description>
		<content:encoded><![CDATA[<p>Just managed to implement it after almost four years. Took some time, but I managed to do it in O(N^2).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Preeti</title>
		<link>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/comment-page-1/#comment-405387</link>
		<dc:creator><![CDATA[Preeti]]></dc:creator>
		<pubDate>Fri, 22 Apr 2016 12:28:50 +0000</pubDate>
		<guid isPermaLink="false">/?p=3439#comment-405387</guid>
		<description><![CDATA[I am not able to understand the pseudocode.Please help me.]]></description>
		<content:encoded><![CDATA[<p>I am not able to understand the pseudocode.Please help me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xavier</title>
		<link>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/comment-page-1/#comment-394720</link>
		<dc:creator><![CDATA[xavier]]></dc:creator>
		<pubDate>Thu, 21 Jan 2016 18:39:40 +0000</pubDate>
		<guid isPermaLink="false">/?p=3439#comment-394720</guid>
		<description><![CDATA[would this work with a loop-tree, one where an edge is added between exactly one of the leaves and another node in the tree?]]></description>
		<content:encoded><![CDATA[<p>would this work with a loop-tree, one where an edge is added between exactly one of the leaves and another node in the tree?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Boody</title>
		<link>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/comment-page-1/#comment-391478</link>
		<dc:creator><![CDATA[Boody]]></dc:creator>
		<pubDate>Thu, 31 Dec 2015 04:41:15 +0000</pubDate>
		<guid isPermaLink="false">/?p=3439#comment-391478</guid>
		<description><![CDATA[Good morning ,

Could anyone solve this question ??
or explain it for me !!

(Kruskal)
Give an example of a family of graphs with n nodes and O(n) edges such that a naive implementation
of the union-find data structure without union-by-rank and path compression
leads to quadratic running time for Kruskal’s algorithm.]]></description>
		<content:encoded><![CDATA[<p>Good morning ,</p>
<p>Could anyone solve this question ??<br />
or explain it for me !!</p>
<p>(Kruskal)<br />
Give an example of a family of graphs with n nodes and O(n) edges such that a naive implementation<br />
of the union-find data structure without union-by-rank and path compression<br />
leads to quadratic running time for Kruskal’s algorithm.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nora</title>
		<link>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/comment-page-1/#comment-207040</link>
		<dc:creator><![CDATA[nora]]></dc:creator>
		<pubDate>Thu, 04 Dec 2014 09:56:26 +0000</pubDate>
		<guid isPermaLink="false">/?p=3439#comment-207040</guid>
		<description><![CDATA[Hi!
Is it possible to let the user chose the graphe by puting  the value in the form?
and How can we do it ?And how can we store the graph that we have to use to find the tree whith kruskal algorithm?]]></description>
		<content:encoded><![CDATA[<p>Hi!<br />
Is it possible to let the user chose the graphe by puting  the value in the form?<br />
and How can we do it ?And how can we store the graph that we have to use to find the tree whith kruskal algorithm?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Victor</title>
		<link>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/comment-page-1/#comment-18665</link>
		<dc:creator><![CDATA[Victor]]></dc:creator>
		<pubDate>Mon, 06 May 2013 21:12:13 +0000</pubDate>
		<guid isPermaLink="false">/?p=3439#comment-18665</guid>
		<description><![CDATA[I&#039;m triying to program this algorithm with C++ 
I need to keep the size of the distance matrix variable...
Any suggestions?
Thanks]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m triying to program this algorithm with C++<br />
I need to keep the size of the distance matrix variable&#8230;<br />
Any suggestions?<br />
Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin</title>
		<link>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/comment-page-1/#comment-17611</link>
		<dc:creator><![CDATA[Martin]]></dc:creator>
		<pubDate>Wed, 05 Dec 2012 10:44:01 +0000</pubDate>
		<guid isPermaLink="false">/?p=3439#comment-17611</guid>
		<description><![CDATA[Hi, indeed a great work here in the first place. Keep going!

In step 2, you are saying to make empty set out of each vertex of G. In my opinion, it shall be 1-element set containing exactly the given vertex. After in the loop, if the vertices are in different components, the sets containing u and v are joined.]]></description>
		<content:encoded><![CDATA[<p>Hi, indeed a great work here in the first place. Keep going!</p>
<p>In step 2, you are saying to make empty set out of each vertex of G. In my opinion, it shall be 1-element set containing exactly the given vertex. After in the loop, if the vertices are in different components, the sets containing u and v are joined.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stoimen</title>
		<link>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/comment-page-1/#comment-17196</link>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
		<pubDate>Tue, 13 Nov 2012 14:33:38 +0000</pubDate>
		<guid isPermaLink="false">/?p=3439#comment-17196</guid>
		<description><![CDATA[For the curious readers, here&#039;s the PHP implementation of Kruskal&#039;s algorithm.

&lt;pre lang=&quot;PHP&quot;&gt;
// the graph
$G = array(
    0 =&gt; array( 0,  4,  0,  0,  0,  0,  0,  0,  8),
    1 =&gt; array( 4,  0,  8,  0,  0,  0,  0,  0,  11),
    2 =&gt; array( 0,  8,  0,  7,  0,  4,  2,  0,  0),
    3 =&gt; array( 0,  0,  7,  0,  9,  14,  0,  0,  0),
    4 =&gt; array( 0,  0,  0,  9,  0,  10,  0,  0,  0),
    5 =&gt; array( 0,  0,  4,  14,  10,  0,  0,  2,  0),
    6 =&gt; array( 0,  0,  2,  0,  0,  0,  0,  6,  7),
    7 =&gt; array( 0,  0,  0,  0,  0,  2,  6,  0,  1),
    8 =&gt; array( 8,  11,  0,  0,  0,  0,  7,  1,  0),
);

function Kruskal(&amp;$G)
{
    $len = count($G);
    
    // 1. Make T the empty tree (we&#039;ll modify the array G to keep only MST
    $T = array();
    
    // 2. Make a single node trees (sets) out of each vertex
    $S = array();
    foreach (array_keys($G) as $k) {
        $S[$k] = array($k);
    }
    
    // 3. Sort the edges
    $weights = array();
    for ($i = 0; $i &lt; $len; $i++) {
        for ($j = 0; $j &lt; $i; $j++) {
            if (!$G[$i][$j]) continue;
            
            $weights[$i . &#039; &#039; . $j] = $G[$i][$j];
        }
    }
    asort($weights);
    
    foreach ($weights as $k =&gt; $w) {
        list($i, $j) = explode(&#039; &#039;, $k);
        
        $iSet = find_set($S, $i);
        $jSet = find_set($S, $j);
        if ($iSet != $jSet) {
            $T[] = &quot;Edge: ($i, $j)&quot;;
            union_sets($S, $iSet, $jSet);
        }
    }
    
    return $T;
}

function find_set(&amp;$set, $index)
{
    foreach ($set as $k =&gt; $v) {
        if (in_array($index, $v)) {
            return $k;
        }
    }
    
    return false;
}

function union_sets(&amp;$set, $i, $j)
{
    $a = $set[$i];
    $b = $set[$j];
    unset($set[$i], $set[$j]);
    $set[] = array_merge($a, $b);
}

$mst = Kruskal($G);

//Edge: (8, 7)
//Edge: (6, 2)
//Edge: (7, 5)
//Edge: (1, 0)
//Edge: (5, 2)
//Edge: (3, 2)
//Edge: (2, 1)
//Edge: (4, 3)
foreach ($mst as $v) {
    echo $v . PHP_EOL;
}
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>For the curious readers, here&#8217;s the PHP implementation of Kruskal&#8217;s algorithm.</p>
<pre lang="PHP">
// the graph
$G = array(
    0 => array( 0,  4,  0,  0,  0,  0,  0,  0,  8),
    1 => array( 4,  0,  8,  0,  0,  0,  0,  0,  11),
    2 => array( 0,  8,  0,  7,  0,  4,  2,  0,  0),
    3 => array( 0,  0,  7,  0,  9,  14,  0,  0,  0),
    4 => array( 0,  0,  0,  9,  0,  10,  0,  0,  0),
    5 => array( 0,  0,  4,  14,  10,  0,  0,  2,  0),
    6 => array( 0,  0,  2,  0,  0,  0,  0,  6,  7),
    7 => array( 0,  0,  0,  0,  0,  2,  6,  0,  1),
    8 => array( 8,  11,  0,  0,  0,  0,  7,  1,  0),
);

function Kruskal(&#038;$G)
{
    $len = count($G);
    
    // 1. Make T the empty tree (we'll modify the array G to keep only MST
    $T = array();
    
    // 2. Make a single node trees (sets) out of each vertex
    $S = array();
    foreach (array_keys($G) as $k) {
        $S[$k] = array($k);
    }
    
    // 3. Sort the edges
    $weights = array();
    for ($i = 0; $i < $len; $i++) {
        for ($j = 0; $j < $i; $j++) {
            if (!$G[$i][$j]) continue;
            
            $weights[$i . ' ' . $j] = $G[$i][$j];
        }
    }
    asort($weights);
    
    foreach ($weights as $k => $w) {
        list($i, $j) = explode(' ', $k);
        
        $iSet = find_set($S, $i);
        $jSet = find_set($S, $j);
        if ($iSet != $jSet) {
            $T[] = "Edge: ($i, $j)";
            union_sets($S, $iSet, $jSet);
        }
    }
    
    return $T;
}

function find_set(&#038;$set, $index)
{
    foreach ($set as $k => $v) {
        if (in_array($index, $v)) {
            return $k;
        }
    }
    
    return false;
}

function union_sets(&#038;$set, $i, $j)
{
    $a = $set[$i];
    $b = $set[$j];
    unset($set[$i], $set[$j]);
    $set[] = array_merge($a, $b);
}

$mst = Kruskal($G);

//Edge: (8, 7)
//Edge: (6, 2)
//Edge: (7, 5)
//Edge: (1, 0)
//Edge: (5, 2)
//Edge: (3, 2)
//Edge: (2, 1)
//Edge: (4, 3)
foreach ($mst as $v) {
    echo $v . PHP_EOL;
}
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
