Indicate whether the following sorting algorithms are stable and/or in-place. Al
ID: 3806017 • Letter: I
Question
Indicate whether the following sorting algorithms are stable and/or in-place. Also, provide their time complexity (with justification if needed). Suppose that the for loop header in line 7 of the Counting Sort algorithm (lecture13.ppt Slide #12) is rewritten to for j leftarrow 1 to n Will the algorithm still sort correctly? Is the modified algorithm a stable sorting algorithm? If yes, prove it. Otherwise provide a counterexample. Study the pseudocode and example of Rand-Select on slides #5-8 in Lecturel4.ppt. Use Slide #8 as a model, illustrate the operation of selecting the 4th smallest element on array A = [6 3 16 11 7 1714 8]. Similar to #8, you can use ordinary Partition rather than Rand-Partition, i.e., you always select the first element as the pivotExplanation / Answer
Stable ?
In place ?
Complexity
Merge Sort
Yes
NO
O(N)
Quick Sort
NO
Yes
O(log(n))
Heap Sort
NO
Yes
O(n log n)
Insertion Sort
Yes
Yes
O(1)
Selection Sort
NO
Yes
O(n2
Counting Sort
Yes
NO
O(n)
Radix Sort
Yes
Yes
O(n log n)
---------------------------------------------------------------------------------------------
If you have any query, please feel free to ask.
Thanks a lot.
Stable ?
In place ?
Complexity
Merge Sort
Yes
NO
O(N)
Quick Sort
NO
Yes
O(log(n))
Heap Sort
NO
Yes
O(n log n)
Insertion Sort
Yes
Yes
O(1)
Selection Sort
NO
Yes
O(n2
Counting Sort
Yes
NO
O(n)
Radix Sort
Yes
Yes
O(n log n)