Algorithms | Sorting | Question 5

Given an unsorted array. The array has this property that every element in array is at most k distance from its position in sorted array where k is a positive integer smaller than size of array. Which sorting algorithm can be easily modified for sorting this array and what is the obtainable time complexity?
(A) Insertion Sort with time complexity O(kn)
(B) Heap Sort with time complexity O(nLogk)
(C) Quick Sort with time complexity O(kLogk)
(D) Merge Sort with time complexity O(kLogk)

Answer: (B)

Explanation: See for explanation and implementation.

Quiz of this Question

My Personal Notes arrow_drop_up

Practice Tags :

Recommended Posts:

3.3 Average Difficulty : 3.3/5.0
Based on 3 vote(s)

User Actions