COMPUTER SCIENCE AND ENGINEERING
ALGORITHMS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
Suppose we have a sorted list with n elements. We decide to perform an insertion sort on this already sorted set. How many comparisons will the sort make?
|
n-1
|
|
n
|
|
n (n-1)
|
|
n + 1
|
Explanation:
Detailed explanation-1: -The number of comparisons will be N-1 times the average length of the sorted list.
Detailed explanation-2: -The maximum number of comparisons for an insertion sort is the sum of the first integers. Again, this is O ( n 2 ) . However, in the best case, only one comparison needs to be done on each pass. This would be the case for an already sorted list.
Detailed explanation-3: -If the elements are already sorted, then the time complexity of Quick sort is better than merge sort.
There is 1 question to complete.