Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

ISRO | ISRO CS 2018 | Question 17

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Of the following sorting algorithms, which has a running time that is least dependent on the initial ordering of the input?

(A)

Merge Sort

(B)

Insertion Sort

(C)

Selection Sort

(D)

Quick Sort


Answer: (A)

Explanation:

In Insertion sort if the array is already sorted then it takes O(n) and if it is reverse sorted then it takes O(n2) to sort the array. In Quick sort, if the array is already sorted or if it is reverse sorted then it takes O(n2).The best and worst case performance of Selection is O(n2) only. But if the array is already sorted then less swaps take place. In merge sort, time complexity is O(nlogn) for all the cases and performance is affected least on the order of input sequence. So, option (A) is correct.


Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Last Updated : 10 Jul, 2018
Like Article
Save Article
Similar Reads