<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>handy &#187; BubbleSort</title>
	<atom:link href="http://sirinsevinc.wordpress.com/tag/bubblesort/feed/" rel="self" type="application/rss+xml" />
	<link>http://sirinsevinc.wordpress.com</link>
	<description>java,webservice,javascript,software algorithms</description>
	<lastBuildDate>Mon, 20 Jul 2009 14:24:24 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='sirinsevinc.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/22dbbb1103eab00233fa34b9029d78b4?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>handy &#187; BubbleSort</title>
		<link>http://sirinsevinc.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sirinsevinc.wordpress.com/osd.xml" title="handy" />
		<item>
		<title>BubbleSort</title>
		<link>http://sirinsevinc.wordpress.com/2008/02/17/bubblesort/</link>
		<comments>http://sirinsevinc.wordpress.com/2008/02/17/bubblesort/#comments</comments>
		<pubDate>Sun, 17 Feb 2008 20:37:23 +0000</pubDate>
		<dc:creator>sirin sevinc</dc:creator>
				<category><![CDATA[Sorting Algorithms]]></category>
		<category><![CDATA[BubbleSort]]></category>

		<guid isPermaLink="false">http://sirinsevinc.wordpress.com/?p=17</guid>
		<description><![CDATA[ Bubble sort has best-case complexity O(n). When a list is already sorted, bubblesort will pass through the list once, and find that it does not need to swap any elements. Thus bubblesort will make only n comparisons and determine that list is completely sorted. It will also use considerably less time O(n2) than if [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sirinsevinc.wordpress.com&blog=2562058&post=17&subd=sirinsevinc&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p> Bubble sort has best-case complexity O(n). When a list is already sorted, bubblesort will pass through the list once, and find that it does not need to swap any elements. Thus bubblesort will make only n comparisons and determine that list is completely sorted. It will also use considerably less time O(n<sup>2</sup>) than if the elements in the unsorted list are not too far from their sorted places.</p>
<div style="background-color:rgb(245, 245, 245);"><code style="font-size:9pt;"><br />
public class BubbleSort {<br />
int[] data;<br />
public BubbleSort(int[] data) {<br />
super();<br />
this.data = data;<br />
}<br />
public int[] sort() {<br />
boolean isSwap = false;<br />
int temp = 0;<br />
do {<br />
isSwap = false;<br />
for (int i = 0; i  data[i + 1]) {<br />
temp = data[i];<br />
data[i] = data[i + 1];<br />
data[i + 1] = temp;<br />
isSwap = true;<br />
}<br />
}<br />
} while (isSwap);<br />
return data;<br />
}<br />
/**<br />
* instead of doing n2 comparisons (and swaps), we can use only<br />
* n + (n-1) + (n-2) + ... + 1 comparisons.<br />
* This sums up to n(n + 1) / 2, which is still<br />
* O(n<sup>2</sup>), but which can be considerably faster in practice.<br />
*<br />
* @return sorted data<br />
*/<br />
public int[] optimezedSort() {<br />
boolean isSwap = false;<br />
int temp = 0;<br />
int n = data.length - 1;<br />
do {<br />
isSwap = false;<br />
n = n - 1;<br />
for (int i = 0; i  data[i + 1]) {<br />
temp = data[i];<br />
data[i] = data[i + 1];<br />
data[i + 1] = temp;<br />
isSwap = true;<br />
}<br />
}<br />
} while (isSwap);<br />
return data;<br />
}<br />
public static void main(String[] args) {<br />
     int[] data = new int[] {1,2,3,4,5,8,6,9,7};<br />
     System.out.println(Arrays.toString(new BubbleSort(data).sort()));<br />
     System.out.println(Arrays.toString(new BubbleSort(data).optimezedSort()));<br />
    }<br />
}</code></div>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sirinsevinc.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sirinsevinc.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sirinsevinc.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sirinsevinc.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sirinsevinc.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sirinsevinc.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sirinsevinc.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sirinsevinc.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sirinsevinc.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sirinsevinc.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sirinsevinc.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sirinsevinc.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sirinsevinc.wordpress.com&blog=2562058&post=17&subd=sirinsevinc&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sirinsevinc.wordpress.com/2008/02/17/bubblesort/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a9d9718257bc3dedcd892134e22b4295?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sirinse</media:title>
		</media:content>
	</item>
	</channel>
</rss>