<?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>slowest algorithms &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/slowest-algorithms/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>Friday Algorithms: JavaScript Bubble Sort</title>
		<link>/2010/07/09/friday-algorithms-javascript-bubble-sort/</link>
		<comments>/2010/07/09/friday-algorithms-javascript-bubble-sort/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 10:20:06 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[algorithms]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Bubble sort]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Insertion sort]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Merge sort]]></category>
		<category><![CDATA[Order theory]]></category>
		<category><![CDATA[Quicksort]]></category>
		<category><![CDATA[slowest algorithms]]></category>
		<category><![CDATA[Sorting]]></category>
		<category><![CDATA[Sorting algorithms]]></category>

		<guid isPermaLink="false">/?p=1780</guid>
		<description><![CDATA[Bubble Sort This is one of the most slowest algorithms for sorting, but it&#8217;s extremely well known because of its easy to implement nature. However as I wrote past Fridays there are lots of sorting algorithms which are really fast, like the quicksort or mergesort. In the case of bubble sort the nature of the &#8230; <a href="/2010/07/09/friday-algorithms-javascript-bubble-sort/" class="more-link">Continue reading <span class="screen-reader-text">Friday Algorithms: JavaScript Bubble Sort</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/06/25/friday-algorithms-sorting-a-set-of-integers-far-quicker-than-quicksort/" rel="bookmark" title="Friday Algorithms: Sorting a Set of Integers &#8211; Far Quicker than Quicksort!">Friday Algorithms: Sorting a Set of Integers &#8211; Far Quicker than Quicksort! </a></li>
<li><a href="/2010/06/18/friday-algorithms-iterative-quicksort/" rel="bookmark" title="Friday Algorithms: Iterative Quicksort">Friday Algorithms: Iterative Quicksort </a></li>
<li><a href="/2010/07/02/friday-algorithms-javascript-merge-sort/" rel="bookmark" title="Friday Algorithms: JavaScript Merge Sort">Friday Algorithms: JavaScript Merge Sort </a></li>
<li><a href="/2012/02/20/computer-algorithms-bubble-sort/" rel="bookmark" title="Computer Algorithms: Bubble Sort">Computer Algorithms: Bubble Sort </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Bubble Sort</h2>
<p><a href="/wp-content/uploads/2010/07/unsorted.jpg"><img class="alignleft size-full wp-image-1788" title="unsorted" src="/wp-content/uploads/2010/07/unsorted.jpg" alt="Unsorted Array" width="250" height="333" srcset="/wp-content/uploads/2010/07/unsorted.jpg 250w, /wp-content/uploads/2010/07/unsorted-225x300.jpg 225w" sizes="(max-width: 250px) 100vw, 250px" /></a></p>
<p>This is one of the most slowest algorithms for sorting, but it&#8217;s extremely well known because of its easy to implement nature. However as I wrote past Fridays there are lots of sorting algorithms which are really fast, like the <a title="Iterative Quicksort" href="/2010/06/18/friday-algorithms-iterative-quicksort/" target="_blank">quicksort</a> or <a title="Merge Sort" href="/2010/07/02/friday-algorithms-javascript-merge-sort/" target="_blank">mergesort</a>. In the case of bubble sort the nature of the algorithm is described in its name. The smaller element goes to the top (beginning) of the array as a bubble goes to the top of the water.</p>
<p>There is a cool animation showing how bubble sort works in compare to the quick sort and you can practically see how slow is bubble sort because of all the comparing.</p>
<p><a href="http://www.youtube.com/watch?v=vxENKlcs2Tw">QuickSort vs. BubbleSort</a></p>
<h2>Pseudo Code</h2>
<p>Actually what I&#8217;d like to show you is how you can move from pseudo code to code in practice. Here&#8217;s the pseudo code from <a href="http://en.wikipedia.org/wiki/Bubble_sort" title="BubbleSort Wikipedia" target="_blank">Wikipedia</a>.</p>
<pre lang="javascript">
procedure bubbleSort( A : list of sortable items ) defined as:
  do
    swapped := false
    for each i in 0 to length(A) - 2 inclusive do:
      if A[i] > A[i+1] then
        swap( A[i], A[i+1] )
        swapped := true
      end if
    end for
  while swapped
end procedure
</pre>
<h2>JavaScript Source</h2>
<pre lang="javascript">
var a = [34, 203, 3, 746, 200, 984, 198, 764, 9];

function bubbleSort(a)
{
    var swapped;
    do {
        swapped = false;
        for (var i=0; i < a.length-1; i++) {
            if (a[i] > a[i+1]) {
                var temp = a[i];
                a[i] = a[i+1];
                a[i+1] = temp;
                swapped = true;
            }
        }
    } while (swapped);
}

bubbleSort(a);
console.log(a);
</pre>
<p>As a result you&#8217;ve a sorted array!</p>
<p><a href="/wp-content/uploads/2010/07/sorted.jpg"><img class="aligncenter size-full wp-image-1790" title="sorted" src="/wp-content/uploads/2010/07/sorted.jpg" alt="Sorted Array" width="430" height="353" srcset="/wp-content/uploads/2010/07/sorted.jpg 430w, /wp-content/uploads/2010/07/sorted-300x246.jpg 300w" sizes="(max-width: 430px) 100vw, 430px" /></a></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/06/25/friday-algorithms-sorting-a-set-of-integers-far-quicker-than-quicksort/" rel="bookmark" title="Friday Algorithms: Sorting a Set of Integers &#8211; Far Quicker than Quicksort!">Friday Algorithms: Sorting a Set of Integers &#8211; Far Quicker than Quicksort! </a></li>
<li><a href="/2010/06/18/friday-algorithms-iterative-quicksort/" rel="bookmark" title="Friday Algorithms: Iterative Quicksort">Friday Algorithms: Iterative Quicksort </a></li>
<li><a href="/2010/07/02/friday-algorithms-javascript-merge-sort/" rel="bookmark" title="Friday Algorithms: JavaScript Merge Sort">Friday Algorithms: JavaScript Merge Sort </a></li>
<li><a href="/2012/02/20/computer-algorithms-bubble-sort/" rel="bookmark" title="Computer Algorithms: Bubble Sort">Computer Algorithms: Bubble Sort </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/07/09/friday-algorithms-javascript-bubble-sort/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
