0

```
#include<stdio.h>
#include<conio.h>
void main()
{
int num[50],i,i1,j,temp = 1,cnt = 0;
printf("How many elements ");
scanf("%d",&i);
printf("Enter the elements ");
for(j = 0;j<i;j++)
{
scanf("%d",&num[j]);
}
i1 = 0;
j=1;
while(i1 < i )
{
for( ;j<i;j++)
{
if((num[j] < num[i1])&& (i1<i))
{
temp = num[j]; //algorithm for sel sort
num[j] = num[i1];
num[i1] = temp;
}
cnt++; //counting iterations
}
i1++;
j=1;
j+=i1;
}
for(j = 0 ;j<i;j++)
printf("\n%d",num[j]);
printf("\n%d ",cnt);
}
```

Hi,

the sel sort algorithm takes n^2 time as per the wiki and what is taught generally(pls correct if wrong) .

where each element is checked every time(i:e loop runs n*n times and values are swapped) . but when i modified the code a bit the algo becomes log n and running more efficiently than bubble sort. so is it that the change has changed meaning and its no more selection sort.

*Edited 6 Years Ago by Rahul.menon*: n/a