<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-9084395895739089540</id><updated>2024-09-06T08:11:59.214+05:30</updated><title type='text'>Ankush Bisht&#39;s Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ankushbisht.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9084395895739089540/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://ankushbisht.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ankush Bisht</name><uri>http://www.blogger.com/profile/00914290252380314787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglRaWm8V9yCAay4Y0i4Mm_uHXH0DGSHDifB0hBw1N99AMTZMMXD_pXnoJo_ktYJ6PKCHBZpxz0vi3ChbEiIFvravE4h0ieDcmjEa9-lYMXuv7kXz1WhlOyGxNpwhOKP3M/s113/Me.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-9084395895739089540.post-4841438848705215249</id><published>2010-02-14T00:46:00.003+05:30</published><updated>2010-02-19T20:50:22.896+05:30</updated><title type='text'>Sorting : The most common and interesting area in algorithms</title><content type='html'>&lt;div style=&quot;margin: 0pt auto; width: 95%;&quot;&gt; 		&lt;div class=&quot;php&quot;&gt;&lt;ol&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;Dear Friends&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;             I like the sorting algorithms very much and want to share some simplest implementations of sorting algorithms&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;Selection &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; is a sorting algorithm&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; specifically an in&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;place comparison &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; It has O&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;n2&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; complexity&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; making it inefficient on large lists&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; and generally performs worse than the similar insertion &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; Selection &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; is noted &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; its simplicity&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; and also has performance advantages over more complicated algorithms in certain situations&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;Here is the implementation&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt;/*&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      Main.java&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      Copyright 2010 Ankush Bisht &lt;ankushbisht18@gmail.com&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      This program is free software; you can redistribute it and/or modify&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      it under the terms of the GNU General Public License as published by&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      the Free Software Foundation; either version 2 of the License, or&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      (at your option) any later version.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      This program is distributed in the hope that it will be useful,&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      GNU General Public License for more details.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      You should have received a copy of the GNU General Public License&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      along with this program; if not, write to the Free Software&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      MA 02110-1301, USA.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;import java&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;util&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;Scanner&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Main &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; static void main &lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;String args&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        Scanner in&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;new&lt;/span&gt; Scanner&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;in&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Enter number of elements in the array&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        int n&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;in&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;nextInt&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        int a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;new&lt;/span&gt; int&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;n&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        int i&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;temp&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Enter &quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot; numbers&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;in&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;nextInt&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&gt;&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;                &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                temp&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;temp&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;            &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;            &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;Insertion &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; is a simple sorting algorithm&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; a comparison &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; in which the sorted &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;array&lt;/span&gt;&lt;/a&gt; &lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;or &lt;a href=&quot;http://www.php.net/list&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;list&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; is built one entry at a &lt;a href=&quot;http://www.php.net/time&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;time&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; It is much less efficient on large lists than more advanced algorithms such &lt;span class=&quot;kw1&quot;&gt;as&lt;/span&gt; quicksort&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; heapsort&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; or merge &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; However&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; insertion &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; provides several advantages&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; simple implementation&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;    &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; efficient &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;quite&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; small data sets&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; adaptive&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; i&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;e&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; efficient &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; data sets that are already substantially sorted&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt; the &lt;a href=&quot;http://www.php.net/time&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;time&lt;/span&gt;&lt;/a&gt; complexity is O&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;n &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; d&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; where d is the number of inversions&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; more efficient in practice than most other simple quadratic &lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;e&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; O&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;n2&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; algorithms such &lt;span class=&quot;kw1&quot;&gt;as&lt;/span&gt; selection &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; or bubble &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt; the average running &lt;a href=&quot;http://www.php.net/time&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;time&lt;/span&gt;&lt;/a&gt; is n2&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;citation needed&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; and the running &lt;a href=&quot;http://www.php.net/time&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;time&lt;/span&gt;&lt;/a&gt; is linear in the best &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; stable&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; i&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;e&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; does not change the relative order of elements with equal keys&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; in&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;place&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; i&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;e&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; only requires a &lt;a href=&quot;http://www.php.net/constant&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;constant&lt;/span&gt;&lt;/a&gt; amount O&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; of additional memory space&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;    &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; online&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; i&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;e&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; can &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; a &lt;a href=&quot;http://www.php.net/list&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;list&lt;/span&gt;&lt;/a&gt; &lt;span class=&quot;kw1&quot;&gt;as&lt;/span&gt; it receives it&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;Most humans when sorting—ordering a deck of cards&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt; example—&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; a method that is similar to insertion &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;Here is the implementation&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt;/*&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      Insertion.java&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      Copyright 2010 Ankush &lt;ankushbisht18@gmail.com&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      This program is free software; you can redistribute it and/or modify&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      it under the terms of the GNU General Public License as published by&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      the Free Software Foundation; either version 2 of the License, or&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      (at your option) any later version.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      This program is distributed in the hope that it will be useful,&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      GNU General Public License for more details.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      You should have received a copy of the GNU General Public License&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      along with this program; if not, write to the Free Software&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      MA 02110-1301, USA.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;import java&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;util&lt;span class=&quot;sy0&quot;&gt;.*;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Insertion &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; static void main &lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;String args&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;       &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        Scanner in&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;new&lt;/span&gt; Scanner&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;in&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        int i&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;a href=&quot;http://www.php.net/key&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Enter number of elements in the array&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        n&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;in&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;nextInt&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        int &lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;new&lt;/span&gt; int &lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;n&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Enter &quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot; numbers&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;in&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;nextInt&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;             &lt;a href=&quot;http://www.php.net/key&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&gt;&lt;/span&gt;key&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;            &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;  &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                j&lt;span class=&quot;sy0&quot;&gt;--;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;a href=&quot;http://www.php.net/key&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;key&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;nu0&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;Bubble &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; is a simple sorting algorithm&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; It works by repeatedly stepping through the &lt;a href=&quot;http://www.php.net/list&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;list&lt;/span&gt;&lt;/a&gt; to be sorted&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; comparing &lt;a href=&quot;http://www.php.net/each&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;each&lt;/span&gt;&lt;/a&gt; pair of adjacent items and swapping them &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; they are in the wrong order&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; The pass through the &lt;a href=&quot;http://www.php.net/list&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;list&lt;/span&gt;&lt;/a&gt; is repeated until no swaps are needed&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; which indicates that the &lt;a href=&quot;http://www.php.net/list&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;list&lt;/span&gt;&lt;/a&gt; is sorted&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; The algorithm gets its name from the way smaller elements &lt;span class=&quot;st0&quot;&gt;&quot;bubble&quot;&lt;/span&gt; to the top of the &lt;a href=&quot;http://www.php.net/list&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;list&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; Because it only uses comparisons to operate on elements&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; it is a comparison &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;Bubble &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; has worst&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; and average complexity both &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;co2&quot;&gt;#1054;(n²), where n is the number of items being sorted. There exist many sorting algorithms with substantially better worst-case or average complexity of O(n log n). Even other &amp;#1054;(n²) sorting algorithms, such as Insertion sort, tend to have better performance than bubble sort. Therefore bubble sort is not a practical sorting algorithm when n is large.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;However&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; one significant advantage that bubble &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; has over most other implementations&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; even QuickSort&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; is that the ability to detect that the &lt;a href=&quot;http://www.php.net/list&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;list&lt;/span&gt;&lt;/a&gt; is sorted is efficiently built into the algorithm&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; Performance of bubble &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; over an already&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;sorted &lt;a href=&quot;http://www.php.net/list&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;list&lt;/span&gt;&lt;/a&gt; &lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;best&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; is O&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;n&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; By contrast&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; most other algorithms&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; even those with better average&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; complexity&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; perform their entire sorting process on the set and thus are more complex&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; However&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; Insertion &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; also has this mechanism&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; and also performs better on a &lt;a href=&quot;http://www.php.net/list&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;list&lt;/span&gt;&lt;/a&gt; that is substantially sorted &lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;having a small number of inversions&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;Here is its implementation&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt;/*&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      Main.java&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      Copyright 2010 Ankush Bisht &lt;ankushbisht18@gmail.com&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      This program is free software; you can redistribute it and/or modify&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      it under the terms of the GNU General Public License as published by&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      the Free Software Foundation; either version 2 of the License, or&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      (at your option) any later version.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      This program is distributed in the hope that it will be useful,&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      GNU General Public License for more details.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      You should have received a copy of the GNU General Public License&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      along with this program; if not, write to the Free Software&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      MA 02110-1301, USA.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;import java&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;util&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;Scanner&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Main &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; static void main &lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;String args&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;       &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        Scanner in&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;new&lt;/span&gt; Scanner&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;in&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        int i&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;temp&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;k&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Enter number of elements in the array&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        n&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;in&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;nextInt&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        int &lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;new&lt;/span&gt; int &lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;n&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Enter &quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot; numbers&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;in&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;nextInt&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;                &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&gt;&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                    temp&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                    a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                    a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;temp&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;                &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;k&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;k&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;k&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;k&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;nu0&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;Quicksort is a well&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;known sorting algorithm developed by C&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; A&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; R&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; Hoare that&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; on average&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; makes &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;co2&quot;&gt;#920;(nlogn) (big O notation) comparisons to sort n items. In the worst case, it makes &amp;#920;(n2) comparisons, though if implemented correctly this behavior is rare. Typically, quicksort is significantly faster in practice than other &amp;#920;(nlogn) algorithms, because its inner loop can be efficiently implemented on most architectures, and in most real-world data, it is possible to make design choices which minimize the probability of requiring quadratic time. Additionally, QuickSort tends to make excellent usage of the memory hierarchy, taking perfect advantage of virtual memory and available caches. Coupled with the fact that QuickSort is an in-place sort and uses no temporary memory, it is very well suited to modern computer architectures.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;Quicksort &lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;also known &lt;span class=&quot;kw1&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&quot;partition-exchange sort&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; is a comparison &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt; and&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; in efficient implementations&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; is not a stable &lt;a href=&quot;http://www.php.net/sort&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;sort&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;Here is its implementation&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt;/*&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      Main.java&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      Copyright 2010 Ankush &lt;ankushbisht18@gmail.com&gt;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      This program is free software; you can redistribute it and/or modify&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      it under the terms of the GNU General Public License as published by&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      the Free Software Foundation; either version 2 of the License, or&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      (at your option) any later version.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      This program is distributed in the hope that it will be useful,&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      GNU General Public License for more details.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      You should have received a copy of the GNU General Public License&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      along with this program; if not, write to the Free Software&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; *      MA 02110-1301, USA.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt; */&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;import java&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;util&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;Scanner&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Main &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;    &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;coMULTI&quot;&gt;/*This method partitions the array into two halves*/&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; static int partition&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;int a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;int p&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;int q&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        int temp&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        int i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;p&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;int j&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;p&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;q&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&lt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;p&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;coMULTI&quot;&gt;/*a[p] is pivot. Here we are taking first element of the array as pivot*/&lt;/span&gt;  &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;            &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;  &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                temp&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;   &lt;span class=&quot;coMULTI&quot;&gt;/*shift elements to left those are less than the pivot and to right those are greater than the pivot*/&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;                a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;temp&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;            &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        temp&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;p&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;coMULTI&quot;&gt;/*shift the pivot to the middle of the array*/&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;p&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;temp&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; i&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; static void quickSort&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;int a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;int p&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;int q&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;p&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;q&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;     &lt;span class=&quot;coMULTI&quot;&gt;/*If p=q then there is only one element or no element so the array is already sorted*/&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            int r&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;partition&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;p&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;q&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            quickSort&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;p&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;r&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;   &lt;span class=&quot;coMULTI&quot;&gt;/*recursive call to first half*/&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            quickSort&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;r&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;q&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;     &lt;span class=&quot;coMULTI&quot;&gt;/*recursive call to second half*/&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; static void main &lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;String args&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;     &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;      &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        Scanner in&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;new&lt;/span&gt; Scanner&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;in&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Enter number of elements in the array&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        int n&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;in&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;nextInt&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        int a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;new&lt;/span&gt; int&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;n&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        int i&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Enter &quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot; numbers&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;in&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;nextInt&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Array before sorting&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;            &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        quickSort&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;n&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;coMULTI&quot;&gt;/*Initial call to method quickSort*/&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Array after sorting&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;            &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;    &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;&lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;There are lot more algorithms to go&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; I will add them later&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt; Please notify me &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; there is any error or mistake anywhere in my implementation and also &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; there is a better implementation of the same&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt; &lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;	&lt;/div&gt;    	</content><link rel='replies' type='application/atom+xml' href='http://ankushbisht.blogspot.com/feeds/4841438848705215249/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ankushbisht.blogspot.com/2010/02/sorting-most-common-and-interesting_14.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9084395895739089540/posts/default/4841438848705215249'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9084395895739089540/posts/default/4841438848705215249'/><link rel='alternate' type='text/html' href='http://ankushbisht.blogspot.com/2010/02/sorting-most-common-and-interesting_14.html' title='Sorting : The most common and interesting area in algorithms'/><author><name>Ankush Bisht</name><uri>http://www.blogger.com/profile/00914290252380314787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglRaWm8V9yCAay4Y0i4Mm_uHXH0DGSHDifB0hBw1N99AMTZMMXD_pXnoJo_ktYJ6PKCHBZpxz0vi3ChbEiIFvravE4h0ieDcmjEa9-lYMXuv7kXz1WhlOyGxNpwhOKP3M/s113/Me.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9084395895739089540.post-5879455149730238322</id><published>2010-02-14T00:23:00.001+05:30</published><updated>2017-01-07T14:18:26.833+05:30</updated><title type='text'>EratosthenesSieve : A very fast algorithm for finding Prime numbers.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div id=&quot;showmore&quot;&gt;
&lt;div id=&quot;code&quot; style=&quot;display: none; width: 98%;&quot;&gt;
&lt;br /&gt;
&lt;strong&gt;CSS (Style):&lt;/strong&gt;&lt;textarea name=&quot;source&quot; style=&quot;height: 200px; width: 100%;&quot;&gt;&lt;style type=&quot;text/css&quot;&gt;&lt;!-- /** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .php .de1, .php .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;color: #000020;} .php {font-family:monospace;color: #006; border: 1px solid #d0d0d0; background-color: #f0f0f0;} .php a:link {color: #000060;} .php a:hover {background-color: #f0f000;} .php .imp {font-weight: bold; color: red;} .php li, .php .li1 {font-weight: normal; vertical-align:top;font: normal normal 130% &#39;Courier New&#39;, Courier, monospace; color: #003030;} .php .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;} .php .li2 {font-weight: bold; vertical-align:top;font-weight: bold; color: #006060;} .php .kw1 {color: #b1b100;} .php .kw2 {color: #000000; font-weight: bold;} .php .kw3 {color: #990000;} .php .kw4 {color: #009900; font-weight: bold;} .php .co1 {color: #666666; font-style: italic;} .php .co2 {color: #666666; font-style: italic;} .php .co3 {color: #0000cc; font-style: italic;} .php .co4 {color: #009933; font-style: italic;} .php .coMULTI {color: #666666; font-style: italic;} .php .es0 {color: #000099; font-weight: bold;} .php .es1 {color: #000099; font-weight: bold;} .php .es2 {color: #660099; font-weight: bold;} .php .es3 {color: #660099; font-weight: bold;} .php .es4 {color: #006699; font-weight: bold;} .php .es5 {color: #006699; font-weight: bold; font-style: italic;} .php .es6 {color: #009933; font-weight: bold;} .php .es_h {color: #000099; font-weight: bold;} .php .br0 {color: #009900;} .php .sy0 {color: #339933;} .php .sy1 {color: #000000; font-weight: bold;} .php .st0 {color: #0000ff;} .php .st_h {color: #0000ff;} .php .nu0 {color: #cc66cc;} .php .nu8 {color: #208080;} .php .nu12 {color: #208080;} .php .nu19 {color:#800080;} .php .me1 {color: #004000;} .php .me2 {color: #004000;} .php .re0 {color: #000088;} .php span.xtra { display:block; } --!&gt;&lt;/style&gt;&lt;/textarea&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Code:&lt;/strong&gt;&lt;textarea name=&quot;source&quot; style=&quot;height: 400px; width: 100%;&quot;&gt;&lt;div class=&quot;php&quot;&gt;
&lt;ol&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt;/*&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      EratosthenesSieve.java&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      Copyright 2010 Ankush Bisht &lt;ankushbisht18@gmail.com&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      This program is free software; you can redistribute it and/or modify&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      it under the terms of the GNU General Public License as published by&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      the Free Software Foundation; either version 2 of the License, or&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      (at your option) any later version.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      This program is distributed in the hope that it will be useful,&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      GNU General Public License for more details.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      You should have received a copy of the GNU General Public License&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      along with this program; if not, write to the Free Software&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      MA 02110-1301, USA.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; */&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
 &lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; EratosthenesSieve &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
 &lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; static void main &lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;String args&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;       &lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Enter the Number till you want to print the Primes&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
        int a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;new&lt;/span&gt; int&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;new&lt;/span&gt; java&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;util&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;Scanner&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;in&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;nextInt&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;int i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
        a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
        int i&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;k&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;step&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
                &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
                &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
                k&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
                step&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
                &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;k&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;+=&lt;/span&gt;step&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
                a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
                &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
        &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Prime Numbers between 1 and 100 are: &quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
        &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&lt;&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
        &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
            &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
            &lt;a href=&quot;http://www.php.net/system&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
        &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
    &lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/textarea&gt;  &lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin: 0pt auto; width: 95%;&quot;&gt;
&lt;div class=&quot;php&quot;&gt;
&lt;ol&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt;/*&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      EratosthenesSieve.java&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      Copyright 2010 Ankush Bisht &lt;ankushbisht18 gmail.com=&quot;&quot;&gt;&lt;/ankushbisht18&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      This program is free software; you can redistribute it and/or modify&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      it under the terms of the GNU General Public License as published by&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      the Free Software Foundation; either version 2 of the License, or&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      (at your option) any later version.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      This program is distributed in the hope that it will be useful,&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      GNU General Public License for more details.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      &lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      You should have received a copy of the GNU General Public License&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      along with this program; if not, write to the Free Software&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; *      MA 02110-1301, USA.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
&lt;span class=&quot;coMULTI&quot;&gt; */&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; EratosthenesSieve &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; static void main &lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;String args&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;       &lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Enter the Number till you want to print the Primes&quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
int a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;new&lt;/span&gt; int&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;new&lt;/span&gt; java&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;util&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;Scanner&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;in&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;nextInt&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;int i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
int i&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;k&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;step&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
&lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
k&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
step&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;k&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;j&lt;span class=&quot;sy0&quot;&gt;+=&lt;/span&gt;step&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;j&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot;Prime Numbers between 1 and &quot;+a.length+&quot; are: &quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;length&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;br0&quot;&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;kw3&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;println&lt;span class=&quot;br0&quot;&gt;(&lt;/span&gt;a&lt;span class=&quot;br0&quot;&gt;[&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li2&quot;&gt;&lt;div class=&quot;de2&quot;&gt;
&lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;li1&quot;&gt;&lt;div class=&quot;de1&quot;&gt;
&lt;span class=&quot;br0&quot;&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;lineitem fade fontsm&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://www.google-analytics.com/urchin.js&quot; type=&quot;text/javascript&quot;&gt;
  
&lt;/script&gt;  &lt;script type=&quot;text/javascript&quot;&gt;
  _uacct = &quot;UA-345477-8&quot;;  urchinTracker();  
&lt;/script&gt;  &lt;ankushbisht18 gmail.com=&quot;&quot;&gt;&lt;a .length=&quot;&quot; href=&quot;https://www.blogger.com/null&quot; i=&quot;&quot;&gt;&lt;/a&gt;&lt;a .length=&quot;&quot; href=&quot;https://www.blogger.com/null&quot; i=&quot;&quot;&gt;&lt;/a&gt;&lt;a .length=&quot;&quot; href=&quot;https://www.blogger.com/null&quot; j=&quot;&quot; step=&quot;&quot;&gt;&lt;/a&gt;&lt;a .length=&quot;&quot; href=&quot;https://www.blogger.com/null&quot; i=&quot;&quot;&gt;&lt;/a&gt;&lt;/ankushbisht18&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://ankushbisht.blogspot.com/feeds/5879455149730238322/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ankushbisht.blogspot.com/2010/02/eratosthenessieve-very-fast-algorithm.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9084395895739089540/posts/default/5879455149730238322'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9084395895739089540/posts/default/5879455149730238322'/><link rel='alternate' type='text/html' href='http://ankushbisht.blogspot.com/2010/02/eratosthenessieve-very-fast-algorithm.html' title='EratosthenesSieve : A very fast algorithm for finding Prime numbers.'/><author><name>Ankush Bisht</name><uri>http://www.blogger.com/profile/00914290252380314787</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglRaWm8V9yCAay4Y0i4Mm_uHXH0DGSHDifB0hBw1N99AMTZMMXD_pXnoJo_ktYJ6PKCHBZpxz0vi3ChbEiIFvravE4h0ieDcmjEa9-lYMXuv7kXz1WhlOyGxNpwhOKP3M/s113/Me.jpg'/></author><thr:total>0</thr:total></entry></feed>