<?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>MobKool Blog &#187; Algorithms</title>
	<atom:link href="http://mobkool.com/topic/algorithms/feed/" rel="self" type="application/rss+xml" />
	<link>http://mobkool.com</link>
	<description>Nihil est incertius vulgo - Cicero.   Except for the Kool - Me</description>
	<lastBuildDate>Tue, 13 Jul 2010 16:17:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP Insertion Sort</title>
		<link>http://mobkool.com/2010/02/10/php-insertion-sort/</link>
		<comments>http://mobkool.com/2010/02/10/php-insertion-sort/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 20:38:45 +0000</pubDate>
		<dc:creator>JFP</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://mobkool.com/?p=417</guid>
		<description><![CDATA[Insertion sorts are good when your data is already partially sorted, or if you have a small collection to sort. That&#8217;s about the best I can say for them. Here&#8217;s two versions in PHP. The first uses two functions: function insertion_sort($a) { for ($i=1; $i < count($a); $i++) { inserter(&#038;$a,$i,$a[$i]); } } function inserter($a,$pos,$a_value) { [...]]]></description>
			<content:encoded><![CDATA[<p>Insertion sorts are good when your data is already partially sorted, or if you have a small collection to sort. That&#8217;s about the best I can say for them. Here&#8217;s two versions in PHP. The first uses two functions:<br />
<code><br />
function insertion_sort($a)<br />
{<br />
     for ($i=1; $i < count($a); $i++)<br />
     {<br />
         inserter(&#038;$a,$i,$a[$i]);<br />
     }<br />
}<br />
</code><br />
<code><br />
function inserter($a,$pos,$a_value)<br />
{<br />
     $temp = $a[$pos];<br />
     $i = $pos;<br />
     while($i >= 0 &#038;&#038; $a[$i-1] > $a_value)<br />
     {<br />
         $a[$i] = $a[$i-1];<br />
         $i = $i-1;<br />
     }<br />
     $a[$i] = $temp;<br />
}<br />
</code></p>
<p>The second uses one function:</p>
<p><code><br />
function insertion_sort($a)<br />
{<br />
	for($j=1; $j < count($a); $j++)<br />
       {<br />
	        $temp = $a[$j];<br />
	        $i = $j;<br />
	        while(($i >= 0) &#038;&#038; ($a[$i-1] > $temp)){<br />
	                $a[$i] = $a[$i-1];<br />
	                $i--;<br />
	        }<br />
	        $a[$i] = $temp;<br />
	}<br />
}<br />
</code></p>
<p>To test them, use the following code:</p>
<p><code><br />
$haystack = array(1,5,6,3);<br />
insertion_sort(&#038;$haystack);<br />
print_r ($haystack);<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mobkool.com/2010/02/10/php-insertion-sort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Sequential or Linear Search Algorithm</title>
		<link>http://mobkool.com/2010/02/08/php-sequential-or-linear-search-algorithm/</link>
		<comments>http://mobkool.com/2010/02/08/php-sequential-or-linear-search-algorithm/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 22:07:04 +0000</pubDate>
		<dc:creator>JFP</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://mobkool.com/?p=406</guid>
		<description><![CDATA[Sequential search, or linear search, is the simplest searching algorithm. Indeed, given it&#8217;s brute force approach of just traversing a collection from the first to last element, it&#8217;s hard to justify calling it an algorithm at all. However, here&#8217;s an example in PHP: function sequential_search($needle,$haystack) { for($i = 0; $i < count($haystack); $i++) { if [...]]]></description>
			<content:encoded><![CDATA[<p>Sequential search, or linear search, is the simplest searching algorithm. Indeed, given it&#8217;s brute force approach of just traversing a collection from the first to last element, it&#8217;s hard to justify calling it an algorithm at all. However, here&#8217;s an example in PHP:<br />
<code><br />
function sequential_search($needle,$haystack) {<br />
	for($i = 0; $i < count($haystack); $i++) {<br />
		if ($needle == $i)<br />
		 return true;<br />
	}<br />
	return false;<br />
}<br />
</code></p>
<p>Here's an example of how you would use this algorithm to look for the number 3 inside an array:</p>
<p><code><br />
$haystack = array(1,2,3,4);<br />
$needle = 3;<br />
$success = sequential_search($needle, $haystack);<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://mobkool.com/2010/02/08/php-sequential-or-linear-search-algorithm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Bubble Sort</title>
		<link>http://mobkool.com/2007/12/30/php-bubble-sort/</link>
		<comments>http://mobkool.com/2007/12/30/php-bubble-sort/#comments</comments>
		<pubDate>Mon, 31 Dec 2007 04:02:22 +0000</pubDate>
		<dc:creator>JFP</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.mobkool.com/wordpress/2007/12/30/php-bubble-sort/</guid>
		<description><![CDATA[One of an occasional series of posts on PHP algorithms. I found this originally at United Scripters, and bookmarked it for some reason. Code function bubbleSort($array=array()/*could have been a pointer*/){ $lastIndex=sizeof($array)-1; while(true){ $newStartIndex=false; $newLastIndex=0; for($j=($startIndex)?$startIndex:1; $j&#60;=$lastIndex; $j++){ if( $array[$j-1] &#62; $array[$j] ){/*SWAP:*/ $temp=$array[$j-1]; $array[$j-1]=$array[$j]; $array[$j]=$temp; if($newStartIndex===false){$newStartIndex=$j-1;}; $newLastIndex=$j-1; }; } if($newStartIndex===false){return $array;}; $startIndex=$newStartIndex; $lastIndex=$newLastIndex; } /* [...]]]></description>
			<content:encoded><![CDATA[<p>One of an occasional series of posts on PHP algorithms. I found this originally at <a href="http://www.unitedscripters.com/index.html?file=/phps/bubblesort.html">United Scripters</a>, and bookmarked it for some reason.</p>
<p><strong>Code</strong></p>
<p>function bubbleSort($array=array()/*could have been a pointer*/){<br />
$lastIndex=sizeof($array)-1;<br />
while(true){<br />
$newStartIndex=false;<br />
$newLastIndex=0;<br />
for($j=($startIndex)?$startIndex:1; $j&lt;=$lastIndex; $j++){<br />
if( $array[$j-1] &gt; $array[$j] ){/*SWAP:*/<br />
$temp=$array[$j-1];<br />
$array[$j-1]=$array[$j];<br />
$array[$j]=$temp;<br />
if($newStartIndex===false){$newStartIndex=$j-1;};<br />
$newLastIndex=$j-1;<br />
};<br />
}<br />
if($newStartIndex===false){return $array;};<br />
$startIndex=$newStartIndex;<br />
$lastIndex=$newLastIndex;<br />
}<br />
/* keep this comment to reuse freely:<br />
Orwant, Hietaniemi, Macdonald algorithm as Php implemented by:<br />
http://www.unitedscripters.com */<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://mobkool.com/2007/12/30/php-bubble-sort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.266 seconds -->
