2,006 views
3 votes
3 votes

Although merge sort runs in Θ(n lg n) worst-case time, and insertion sort runs in Θ(n 2 ) worst-case time, the constant factors in insertion sort make it faster for small n. Thus, it makes sense to use insertion sort within merge sort when subproblems become sufficiently small. Consider a modification to merge sort in which n/k sublists of length k are sorted using insertion sort and then merged using the standard merging mechanism, where k is a value to be determined.

a. What is the worst-case time to sort the n/k sublists (each of length k)?

b. Show that the sublists can be merged in Θ(n lg(n/k)) worst-case time.

c. What is the largest asymptotic (Θ-notation) value of k as a function of n for which the modified algorithm has the same asymptotic running time as standard merge sort? 

d.How should we choose k in practice?

1 Answer

0 votes
0 votes
(a) In the insertion sort n element sorted time in the worst case is O(n2) time. In the problem k length  takes O(K2)  time .Hence

N/K sublist takes O(nk) times .

If we merge  sorted array using merge procedure it takes nlog(n/k) time .So total time=nk+nlog(n/k) time

Related questions

1 votes
1 votes
1 answer
1
0 votes
0 votes
3 answers
2
radha gogia asked Jul 17, 2015
989 views
If we talk about that since since we cant access any random element in a linked list for that reason quick sort cant be used for linked lists ,then in merge sort also we ...
1 votes
1 votes
0 answers
3
0 votes
0 votes
1 answer
4
LavTheRawkstar asked Jan 12, 2017
840 views
INSERTION-SORT (A, n) ⊳ A[1 . . n]for (j ← 2 to len(A) ){key ← A[ j];i ← j – 1 ; while (i 0 and A[i] key) { A[...