What happens to the number of comparisons for each of the sort algorithms if the list is already sorted.
What will be an ideal response?
The processing of selection and bubble sort, as written, is independent of the original configuration of the items in the list, and therefore remain O(n2). But given that the data is originally sorted, the inner loop of the insertion sort will only make one comparison for each iteration, giving this situation the best case efficiency of O(n).
Because the quick sort algorithm, as written, chooses the first element in the partition as the partition element, each recursive step will only handle one element for an initially sorted list, and the efficiency degrades to the worst case scenario of O(n2). The merge sort guarantees equal partitions, and is O(n log n) in all cases, including this situation in which the elements are initially sorted.
You might also like to view...
To raise a predefined exception within a stored procedure, you use the RAISE statement.
a. true b. false
Which of the following would not be considered hardware?
(a) an operating system (b) a CPU (c) a keyboard (d) a disk