<?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>Ersin Acar &#187; quicksort</title>
	<atom:link href="http://ersinacar.com/tag/quicksort/feed" rel="self" type="application/rss+xml" />
	<link>http://ersinacar.com</link>
	<description>PHP and Web Technologies Freak</description>
	<lastBuildDate>Fri, 06 Jan 2012 14:19:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sorting algorithm- Quicksort</title>
		<link>http://ersinacar.com/sorting-algorithm-quicksort_76.html</link>
		<comments>http://ersinacar.com/sorting-algorithm-quicksort_76.html#comments</comments>
		<pubDate>Tue, 21 Apr 2009 19:08:16 +0000</pubDate>
		<dc:creator>Ersin Acar</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[quicksort]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://ersinacar.com/?p=76</guid>
		<description><![CDATA[Quicksort is one of the fastest and simplest sorting algorithms [Hoa 62]. It works recursively by a divide-and-conquer strategy. The quicksort is considered to be very efficient, with its &#8220;divide and conquer&#8221; algorithm. This sort starts by dividing the original array into two sections (partitions) based upon the value of the first item in the array. [...]]]></description>
			<content:encoded><![CDATA[<p>Quicksort is one of the fastest and simplest sorting algorithms [Hoa 62]. It works recursively by a divide-and-conquer strategy.</p>
<p>The  quicksort is considered to be very efficient,   with its &#8220;divide and conquer&#8221; algorithm.  This sort starts by dividing the original array into two sections (partitions) based upon the value of the first item in the array.  Since our example sorts into descending order, the first section will contain all the elements with values greater than the first item.  <span id="more-76"></span>The second section will contain elements with values less than (or equal to) the first element. It is possible for the first element to end up in either partition.<br />
An example in C</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> swap<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">*</span>a<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>b<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> t<span style="color: #339933;">=*</span>a<span style="color: #339933;">;</span> <span style="color: #339933;">*</span>a<span style="color: #339933;">=*</span>b<span style="color: #339933;">;</span> <span style="color: #339933;">*</span>b<span style="color: #339933;">=</span>t<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> sort<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> arr<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #993333;">int</span> beg<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> end<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>end <span style="color: #339933;">&gt;</span> beg <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">int</span> piv <span style="color: #339933;">=</span> arr<span style="color: #009900;">&#91;</span>beg<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> l <span style="color: #339933;">=</span> beg <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> r <span style="color: #339933;">=</span> end<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>l <span style="color: #339933;">&lt;</span> r<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>arr<span style="color: #009900;">&#91;</span>l<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;=</span> piv<span style="color: #009900;">&#41;</span>
        l<span style="color: #339933;">++;</span>
      <span style="color: #b1b100;">else</span>
        swap<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>arr<span style="color: #009900;">&#91;</span>l<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>arr<span style="color: #009900;">&#91;</span><span style="color: #339933;">--</span>r<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    swap<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>arr<span style="color: #009900;">&#91;</span><span style="color: #339933;">--</span>l<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>arr<span style="color: #009900;">&#91;</span>beg<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    sort<span style="color: #009900;">&#40;</span>arr<span style="color: #339933;">,</span> beg<span style="color: #339933;">,</span> l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    sort<span style="color: #009900;">&#40;</span>arr<span style="color: #339933;">,</span> r<span style="color: #339933;">,</span> end<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Exernal Links:<br />
An interactive demo; http://pages.stern.nyu.edu/~panos/java/Quicksort/<br />
Wiki; http://en.wikipedia.org/wiki/Quicksort</p>
]]></content:encoded>
			<wfw:commentRss>http://ersinacar.com/sorting-algorithm-quicksort_76.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

