//Bubble sort algorithm implementation. Also calculate time complexity.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],temp,i,j,n,count;
count=0;count++;
printf("Bubble Sort\nEnter total no. of values: ");
{
scanf("%d",&n);
count++;
}
printf("Enter the values:-\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
count++;
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(a[j]<a[i])
{
temp=a[j];count++;
a[j]=a[i];count++;
a[i]=temp;count++;
}
count++;
}
count++;
}
printf("Bubble-Sort result:-\n");
for(i=0;i<n;i++)
{
printf("%d\t",a[i]);
count++;
}
printf("\nTime Complexity is: %d",count);
getch();
}
//program written by Mars.
What is the time complexity for this program???
ReplyDeleteFor bubble sort (also for this program)-
ReplyDeleteO(n^2)
best sloutions for this program
ReplyDeletehttp://programmergallery.com/c-program/bubble-sort-algorith-program-using-c-program.php
Networking Related..In This site we write about Cisco examination,Cloud computing,Amazon web services,Big Data analytics,Computer networks and more ...
ReplyDelete