Which of the following sorting techniques have minimum number of comparision in best case?
1. Insertion Sort
2. Selection Sort
3. Merge Sort
4. Heap Sort
5.Quick Sort
The answer is insertion sort but my doubt is in insertion sort algo. inside the for loop the while loop condition is:-
while(i >= 0 && A[i] > Key){.....}
Now if say array is sorted in increasing order the while loop wont execute at all because the number of time while loop executes here = no. of inversions which is Zero in sorted array.But the comparison will be done for all the cases right. Then how come insertion sort possess O(n) number of comparisons in best case.Wont it have O(n^2) Comparisons.Becasue comparisons will be done in all the cases weather its sorted or not.