Wanted to know will it won’t be better if inner loop for traversing unsorted array starts from (i+1) instead of (i) as mentioned in lecture.
Cause comparing (a[i] < a[min_idx]) which is euivalent to (a[i] < a[i]) when j=i
We can have below code as well right? Will below improve computational complexity?
for(i=0;i<n-1;i++)
{
min_idx=i;
for(j=i+1; j<n ; j++)
{
if(a[j] < a[min_idx])
{
min_idx=j;
}
}
swap(a[i],a[min_idx]);