1.

Which of the following sorting algorithm is best suited if the elements are already sorted?(a) Heap Sort(b) Quick Sort(c) Insertion Sort(d) Merge SortI got this question during an online interview.I'd like to ask this question from Insertion sort in chapter Sorting of Data Structures & Algorithms II

Answer»

Right option is (c) INSERTION Sort

The best I can explain: The best case running time of the insertion sort is O(n). The best case occurs when the input ARRAY is ALREADY sorted. As the elements are already sorted, only one comparison is made on each PASS, so that the time required is O(n).



Discussion

No Comment Found

Related InterviewSolutions