<?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>Think Lamp &#187; big o notation</title>
	<atom:link href="http://www.think-lamp.com/tag/big-o-notation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.think-lamp.com</link>
	<description>Everything Linux Apache Php Mysql</description>
	<lastBuildDate>Fri, 18 Feb 2011 01:28:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Sieve of Eratosthenes in PhP</title>
		<link>http://www.think-lamp.com/2008/08/sieve-of-eratosthenes-in-php/</link>
		<comments>http://www.think-lamp.com/2008/08/sieve-of-eratosthenes-in-php/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 03:26:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[big o notation]]></category>
		<category><![CDATA[complexity]]></category>
		<category><![CDATA[Eratosthenes]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://www.think-lamp.com/?p=37</guid>
		<description><![CDATA[Prime Numbers: Positive natural numbers which has exactly two distinct natural number divisors 1 and itself. Sieve Of Eratosthenes is a computer algorithm to find out prime numbers upto a specified integer starting from 2. The time complexity of a unfaithful sieve is Θ(n2/(log n)2) ( regardless of what wikipedia might say ) I tried <a href='http://www.think-lamp.com/2008/08/sieve-of-eratosthenes-in-php/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><strong>Prime Numbers</strong>: Positive natural numbers which has exactly two <strong>distinct</strong> natural number divisors 1 and itself.</p>
<p>Sieve Of Eratosthenes is a computer algorithm to find out prime numbers upto a specified integer starting from 2.<br />
The time complexity of a unfaithful sieve is <span style="color: #993300;"><strong>Θ(n2/(log n)2)</strong></span> ( regardless of what wikipedia might say <img src='http://www.think-lamp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  )</p>
<p><span id="more-37"></span></p>
<p>I tried the program in PhP ( for all the php enthusiast <img src='http://www.think-lamp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ). There is a cool animation ( I found ) for proper understanding:</p>
<div class="wp-caption aligncenter" style="width: 455px"><img title="Sieve of Eratosthenes" src="http://upload.wikimedia.org/wikipedia/commons/c/c8/Animation_Sieve_of_Eratosth-2.gif" alt="Sieve of Eratosthenes in PHP" width="445" height="369" /><p class="wp-caption-text">Sieve of Eratosthenes in PHP</p></div>
<pre class="brush: php;">
/**
* Nishchay Shah                    August 10 2008
*
* Program: To find prime numbers
* Algorithm: Sieve of Eratosthenes
*
* Memory And Time Cost:
*        09552  bytes for 20 numbers        ( 250 to 380 usec )
*        49920 bytes for 100 numbers        ( 1600 to 2500 usec )
*        114.1 K bytes for 500 numbers    ( 230 to 350 msec )
*
*
*/
echo&quot;
&lt;pre&gt;;&quot;; // for browser output
$max = 10;   // find prime numbers till this value. [ Change it for the higher limit. Please dont go crazy.]

/// Populate the scan array
for($i=2;$i&amp;lt;$max;$i++){
$scan[]= $i;
}
/// Call the function
primeNumber($scan);

/// Function to find prime numbers
function primeNumber($scan){
$tempFound = array(); // declare array,save memory
global $primeNumbers;
$number = current($scan); // current data pointer

foreach($scan as $remainingNumber) {
if(!fmod($remainingNumber,$number)){
$tempFound[] = $remainingNumber; //make list of multiples
} // end of if mod = 0
} // end foreach

$scan = array_diff($scan, $tempFound);     // remove the multiples from the list
$primeNumbers[] =  current($scan);
if(count($scan) !=1){
primeNumber($scan);
} // end if count is not 1
else{
return;
}
} // end of function primeNumber

/// Add 2 in the beginning ..
$primeNumbers = array_pad($primeNumbers, -(count($primeNumbers)+2), 0);
$primeNumbers= array(2) + $primeNumbers;
/// Output
print_r($primeNumbers);&lt;/pre&gt;
</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.think-lamp.com%2F2008%2F08%2Fsieve-of-eratosthenes-in-php%2F&amp;linkname=Sieve%20of%20Eratosthenes%20in%20PhP"><img src="http://www.think-lamp.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.think-lamp.com/2008/08/sieve-of-eratosthenes-in-php/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>

