<?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: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-812535901784651486</id><updated>2011-11-27T15:36:14.784-08:00</updated><title type='text'>Algorithm n Algorithms</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://algorithms-computer.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/812535901784651486/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://algorithms-computer.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>রেজওয়ানুল হক</name><uri>http://www.blogger.com/profile/14861213171354105332</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-812535901784651486.post-6550313972964053953</id><published>2008-07-16T08:34:00.000-07:00</published><updated>2008-07-16T09:58:07.158-07:00</updated><title type='text'>Sorting Algorithms in C</title><content type='html'>&lt;span style="font-size:100%;"&gt;Here we will give you the implementation of different sorting algorithms in C language. All the implementations have been tested using "gcc" compiler in cygwin. We have used file input and output.&lt;br /&gt;&lt;br /&gt;Input specification: Input file contains 15,000 integers for each case. The numbers are generated in the input file randomly.&lt;br /&gt;Output specification: Output file contains the numbers in ascending order.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;1. Bubble Sort:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;#include&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;#define SIZE 15000&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;void bubbleSort(unsigned int[]);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;int main(void)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   unsigned int A[SIZE];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   int i,j;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   if(freopen("bubble.in","r",stdin)==NULL)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;       printf("Error Reading File");&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;       exit(1);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   freopen("bubble.out","w",stdout);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   for(i=0;i&amp;lt;SIZE;i++)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;       scanf("%d",&amp;amp;A[i]);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   bubbleSort(A);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   for(i=0;i&amp;lt;SIZE;i++)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;       printf("%d ",A[i]);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   fclose(stdin);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   fclose(stdout);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   return 0;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;void bubbleSort(unsigned int A[])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   unsigned int temp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   int i,j;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   for(i=0;i&amp;lt;SIZE;i++)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;       {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;       for(j=SIZE-1;j&amp;gt;i;j--)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;           if(A[j]&amp;lt;A[j-1])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;               {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;               temp=A[j];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;               A[j]=A[j-1];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;               A[j-1]=temp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;               }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;       }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;   }&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;Input file: bubble.in&lt;br /&gt;Output file: bubble.out&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;Complexity: O(n^2)&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-weight: bold;"&gt;2. Insertion Sort&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new;"&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new;font-size:100%;" &gt;#include&amp;lt;stdlib.h&amp;gt;&lt;br /&gt;#define SIZE 15000&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new;font-size:100%;" &gt;void insertionSort(unsigned int[]);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: courier new;font-size:100%;" &gt;&lt;br /&gt;int main(void)&lt;br /&gt;{&lt;br /&gt;unsigned int A[SIZE];&lt;br /&gt;int i,j;&lt;br /&gt;if(freopen("insertion.in","r",stdin)==NULL)&lt;br /&gt;   {&lt;br /&gt;   printf("Error Reading File");&lt;br /&gt;   exit(1);&lt;br /&gt;   }&lt;br /&gt;freopen("insertion.out","w",stdout);&lt;br /&gt;for(i=0;i&amp;lt; SIZE;i++)&lt;br /&gt;   scanf("%d",&amp;amp;A[i]);&lt;br /&gt;insertionSort(A);&lt;br /&gt;for(i=0;i&amp;lt; SIZE;i++)&lt;br /&gt;   printf("%d ",A[i]);&lt;br /&gt;fclose(stdin);&lt;br /&gt;fclose(stdout);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family: courier new;"&gt;void insertionSort(unsigned int a[])&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;int i,j;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;unsigned int key;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;for(j=1;j&amp;lt; SIZE;j++)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    key = a[j];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    i = j-1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    while(i&gt;=0 &amp;amp;&amp;amp; a[i]&gt;key)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        a[i+1]=a[i];&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        i=i-1;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    a[i+1]=key;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;Input file: insertion.in&lt;br /&gt;Output file: insertion.out&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;Complexity: O(n^2)&lt;br /&gt;&lt;br /&gt;More sorting algorithms to follow..&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/812535901784651486-6550313972964053953?l=algorithms-computer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://algorithms-computer.blogspot.com/feeds/6550313972964053953/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=812535901784651486&amp;postID=6550313972964053953' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/812535901784651486/posts/default/6550313972964053953'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/812535901784651486/posts/default/6550313972964053953'/><link rel='alternate' type='text/html' href='http://algorithms-computer.blogspot.com/2008/07/sorting-algorithms-in-c.html' title='Sorting Algorithms in C'/><author><name>রেজওয়ানুল হক</name><uri>http://www.blogger.com/profile/14861213171354105332</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-812535901784651486.post-3112538435629183047</id><published>2008-07-14T22:02:00.000-07:00</published><updated>2008-07-14T22:05:33.620-07:00</updated><title type='text'>Algorithms</title><content type='html'>In this blog, I will try to give you the simple implementation of different algorithms in C/C++, Java, Python and Haskell. I hope that you will contribute here substantially so that this blog can be very useful for students of computer science.&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;Rezwan&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/812535901784651486-3112538435629183047?l=algorithms-computer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://algorithms-computer.blogspot.com/feeds/3112538435629183047/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=812535901784651486&amp;postID=3112538435629183047' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/812535901784651486/posts/default/3112538435629183047'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/812535901784651486/posts/default/3112538435629183047'/><link rel='alternate' type='text/html' href='http://algorithms-computer.blogspot.com/2008/07/algorithms.html' title='Algorithms'/><author><name>রেজওয়ানুল হক</name><uri>http://www.blogger.com/profile/14861213171354105332</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
