<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bridge &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/bridge/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Computer Algorithms: Kruskal&#8217;s Minimum Spanning Tree</title>
		<link>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/</link>
		<comments>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/#comments</comments>
		<pubDate>Mon, 12 Nov 2012 12:01:47 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[algorithms]]></category>
		<category><![CDATA[data structures]]></category>
		<category><![CDATA[Graphs]]></category>
		<category><![CDATA[Bridge]]></category>
		<category><![CDATA[Distributed minimum spanning tree]]></category>
		<category><![CDATA[Environment]]></category>
		<category><![CDATA[Graph theory]]></category>
		<category><![CDATA[Joseph Kruskal]]></category>
		<category><![CDATA[Kruskal's algorithm]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Minimum spanning tree]]></category>
		<category><![CDATA[minimum spanning tree algorithms]]></category>
		<category><![CDATA[Prim's algorithm]]></category>
		<category><![CDATA[Reverse-delete algorithm]]></category>
		<category><![CDATA[Spanning tree]]></category>
		<category><![CDATA[statistician]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[The algorithm]]></category>
		<category><![CDATA[Theoretical computer science]]></category>
		<category><![CDATA[Tree]]></category>
		<category><![CDATA[two main algorithms]]></category>

		<guid isPermaLink="false">/?p=3439</guid>
		<description><![CDATA[Introduction One of the two main algorithms in finding the minimum spanning tree algorithms is the algorithm of Kruskal. Before getting into the details, let’s get back to the principles of the minimum spanning tree. We have a weighted graph and of all spanning trees we’d like to find the one with minimal weight. As &#8230; <a href="/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/" class="more-link">Continue reading <span class="screen-reader-text">Computer Algorithms: Kruskal&#8217;s Minimum Spanning Tree</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2012/11/19/computer-algorithms-prims-minimum-spanning-tree/" rel="bookmark" title="Computer Algorithms: Prim&#8217;s Minimum Spanning Tree">Computer Algorithms: Prim&#8217;s Minimum Spanning Tree </a></li>
<li><a href="/2012/11/05/computer-algorithms-minimum-spanning-tree/" rel="bookmark" title="Computer Algorithms: Minimum Spanning Tree">Computer Algorithms: Minimum Spanning Tree </a></li>
<li><a href="/2012/06/22/computer-algorithms-binary-search-tree-data-structure/" rel="bookmark" title="Computer Algorithms: Binary Search Tree">Computer Algorithms: Binary Search Tree </a></li>
<li><a href="/2012/07/03/computer-algorithms-balancing-a-binary-search-tree/" rel="bookmark" title="Computer Algorithms: Balancing a Binary Search Tree">Computer Algorithms: Balancing a Binary Search Tree </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Introduction</h2>
<p>One of the two main algorithms in <a href="/2012/11/05/computer-algorithms-minimum-spanning-tree/" title="Computer Algorithms: Minimum Spanning Tree">finding the minimum spanning tree</a> algorithms is the algorithm of Kruskal. Before getting into the details, let’s get back to the principles of the minimum spanning tree. </p>
<p>We have a weighted graph and of all spanning trees we’d like to find the one with minimal weight. As an example on the picture above you see a spanning tree (T) on the graph (G), but that isn&#8217;t the minimum weight spanning tree!</p>
<p><figure id="attachment_3459" style="width: 620px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/11/1.-A-graph-and-a-possible-spanning-tree.png"><img src="/wp-content/uploads/2012/11/1.-A-graph-and-a-possible-spanning-tree.png" alt="A graph and a possible spanning tree" title="A graph and a possible spanning tree" width="620" height="399" class="size-full wp-image-3459" srcset="/wp-content/uploads/2012/11/1.-A-graph-and-a-possible-spanning-tree.png 620w, /wp-content/uploads/2012/11/1.-A-graph-and-a-possible-spanning-tree-300x193.png 300w" sizes="(max-width: 620px) 100vw, 620px" /></a><figcaption class="wp-caption-text">&nbsp;</figcaption></figure><span id="more-3439"></span></p>
<p>We can think of a group of islands and the possible connections of bridges connecting them. Of course building bridges is expensive and time consuming, so we must be aware of what kind of bridges we want to build. Nevertheless there is an important question, what’s the minimum price we’d like to pay to build such set of bridges connecting all the islands. </p>
<figure id="attachment_3457" style="width: 620px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/11/2.-Islands-and-bridges.png"><img src="/wp-content/uploads/2012/11/2.-Islands-and-bridges.png" alt="Islands and bridges" title="Islands and bridges" width="620" height="399" class="size-full wp-image-3457" srcset="/wp-content/uploads/2012/11/2.-Islands-and-bridges.png 620w, /wp-content/uploads/2012/11/2.-Islands-and-bridges-300x193.png 300w" sizes="(max-width: 620px) 100vw, 620px" /></a><figcaption class="wp-caption-text">&nbsp;</figcaption></figure>
<p>Thus we practically need to build a minimum spanning tree, where the vertices will be the islands, while the edges will be the possible bridges between them. Every possible bridge has a weight (the price or the time we need to build it, etc.).</p>
<p>This scenario is only one of possible use cases of where minimum spanning trees can be used in practice.  </p>
<p>The two main approaches – the Kruskal’s and the Prim’s algorithms however differ. </p>
<h2>Overview</h2>
<p>The algorithm of Kruskal starts by initializing a set of |V| trees. </p>
<figure id="attachment_3458" style="width: 620px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/11/3.-A-set-of-V-trees.png"><img src="/wp-content/uploads/2012/11/3.-A-set-of-V-trees.png" alt="A set of V trees" title="A set of V trees" width="620" height="399" class="size-full wp-image-3458" srcset="/wp-content/uploads/2012/11/3.-A-set-of-V-trees.png 620w, /wp-content/uploads/2012/11/3.-A-set-of-V-trees-300x193.png 300w" sizes="(max-width: 620px) 100vw, 620px" /></a><figcaption class="wp-caption-text">&nbsp;</figcaption></figure>
<p>During the process of building the final spanning tree we keep a forest. Obviously we start with a forest with |V| trees, where each tree is a single node tree.</p>
<figure id="attachment_3456" style="width: 620px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/11/4.-A-single-node-tree.png"><img src="/wp-content/uploads/2012/11/4.-A-single-node-tree.png" alt="A single node tree" title="A single node tree" width="620" height="399" class="size-full wp-image-3456" srcset="/wp-content/uploads/2012/11/4.-A-single-node-tree.png 620w, /wp-content/uploads/2012/11/4.-A-single-node-tree-300x193.png 300w" sizes="(max-width: 620px) 100vw, 620px" /></a><figcaption class="wp-caption-text">&nbsp;</figcaption></figure>
<p>On some point we have a forest of “k” trees which are all a sub-trees of the minimum spanning tree. </p>
<figure id="attachment_3455" style="width: 620px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/11/5.-A-forest-out-of-K-sub-trees.png"><img src="/wp-content/uploads/2012/11/5.-A-forest-out-of-K-sub-trees.png" alt="Growing forest" title="Growing forest" width="620" height="399" class="size-full wp-image-3455" srcset="/wp-content/uploads/2012/11/5.-A-forest-out-of-K-sub-trees.png 620w, /wp-content/uploads/2012/11/5.-A-forest-out-of-K-sub-trees-300x193.png 300w" sizes="(max-width: 620px) 100vw, 620px" /></a><figcaption class="wp-caption-text">&nbsp;</figcaption></figure>
<p>Finally one step before building the final MST we have two trees and we connect them with the less weighted edge left that connects them.</p>
<p>It’s important to note that during the process of building the tree we sort the edges in ascending order by their weight.</p>
<figure id="attachment_3454" style="width: 620px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/11/6.-Sorted-Edges.png"><img src="/wp-content/uploads/2012/11/6.-Sorted-Edges.png" alt="Sorted edges" title="Sorted edges" width="620" height="399" class="size-full wp-image-3454" srcset="/wp-content/uploads/2012/11/6.-Sorted-Edges.png 620w, /wp-content/uploads/2012/11/6.-Sorted-Edges-300x193.png 300w" sizes="(max-width: 620px) 100vw, 620px" /></a><figcaption class="wp-caption-text">&nbsp;</figcaption></figure>
<p>Than we start getting edges and check whether their ends (the two vertices making the edge) belong to a different sub-trees.</p>
<figure id="attachment_3453" style="width: 620px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/11/7.-Check-edges.png"><img src="/wp-content/uploads/2012/11/7.-Check-edges.png" alt="Check edges" title="Check edges" width="620" height="399" class="size-full wp-image-3453" srcset="/wp-content/uploads/2012/11/7.-Check-edges.png 620w, /wp-content/uploads/2012/11/7.-Check-edges-300x193.png 300w" sizes="(max-width: 620px) 100vw, 620px" /></a><figcaption class="wp-caption-text">&nbsp;</figcaption></figure>
<h2>Pseudo Code</h2>
<pre>
1. T (the final spanning tree) is defined to be the empty set;
2. For each vertex v of G, make the empty set out of v;
3. Sort the edges of G in ascending (non-decreasing) order;
4. For each edge (u, v) from the sored list of step 3.
      If u and v belong to different sets
         Add (u,v) to T;
         Get together u and v in one single set;
5. Return T
</pre>
<p>A great feature about the Kruskal&#8217;s algorithm is that it also work on disconnected graphs.</p>
<h2>History</h2>
<p>Kruskal’s algorithm is named after <a href="http://en.wikipedia.org/wiki/Joseph_Kruskal" title="Joseph Kruskal" target="_blank">Joseph Kruskal</a>, who wasn’t only computer scientist, but also prominent mathematician and statistician. Although he is best known for its algorithm for computing the minimum spanning tree, described in this post, he’s also known with his work as a statistician and his contribution to the formulation of multidimensional scaling. </p>
<p>Kruskal also explored the Indo-European languages contributing the studies of the linguistics along with other scientists. His “Indo-European Lexicographical List” (http://www.wordgumbo.com/ie/cmp/) is still widely used.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2012/11/19/computer-algorithms-prims-minimum-spanning-tree/" rel="bookmark" title="Computer Algorithms: Prim&#8217;s Minimum Spanning Tree">Computer Algorithms: Prim&#8217;s Minimum Spanning Tree </a></li>
<li><a href="/2012/11/05/computer-algorithms-minimum-spanning-tree/" rel="bookmark" title="Computer Algorithms: Minimum Spanning Tree">Computer Algorithms: Minimum Spanning Tree </a></li>
<li><a href="/2012/06/22/computer-algorithms-binary-search-tree-data-structure/" rel="bookmark" title="Computer Algorithms: Binary Search Tree">Computer Algorithms: Binary Search Tree </a></li>
<li><a href="/2012/07/03/computer-algorithms-balancing-a-binary-search-tree/" rel="bookmark" title="Computer Algorithms: Balancing a Binary Search Tree">Computer Algorithms: Balancing a Binary Search Tree </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/11/12/computer-algorithms-kruskals-minimum-spanning-tree/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
