Which one of the following is the tightest upper bound that represents the number of swaps required to sort $n$ numbers using selection sort?
But the time complexity of Selection Sort is O(n2).. There are two loops, one inside the other
Ok. Thanks Sir... The book from where I read has given wrong algorithm, saying it to be Selection Sort.. As per that algorithm, number of swaps are also O(n2).
swap(a[i],a[min_idx]); // only 1 swap each iteration for a total of n-1 iterations
@Ayush Upadhyaya In this algorithm , the first loop should be
as for the lase element we don't need any comparison.
@Ayush Upadhyaya typing mistake at j=i+1
edit i want to say that it should be i+1 but typed as i+i
@Nandkishor3939-$i \lt n-1$ will ensure last value at which loop runs is $n-2$ only.
@Gurdeep Saini-Why j should not be $i+1$ ? :O