Although merge sort runs in Theta (nlgn) worst-case time and insertion sort runs
ID: 3885110 • Letter: A
Question
Although merge sort runs in Theta (nlgn) worst-case time and insertion sort runs in Theta(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) Show that the n/k sublists, each of length k, can be sorted by insertion sort in Theta(n/k) worst-case time. b) Show that the sublists can be merged in Theta (nlg(n/k)) worst-case time. c) How should k be chosen in practice? Let f(n) and g(n) be asymptotically nonnegative functions. Using the basic definition of Theta - notation, prove that max (f(n), g(n)) = Theta(f(n) + g(n)). Is 2^n + 1 = 0 (2^n)? Is 2^2n = 0(2^n)? Why, please provide detailed reasoning.Explanation / Answer
A) Insertion sort takes 0012) time per k-element list in worst case time. consequently
Sorting nil: such k—factor lists, take 0(k2nlk) = O (nlc) worst case time.
B) The type idea is to merge the list pair wise, and after that merge the resultant lists pair
Wise until there is only one list the pair wise merging requires 0(n) work at
Each level, since we are still working on n elements, even if they are
partition among sub lists. The number of levels, starting with nflc, k.-
Element list and finishing with l n - element list, is [13031101, therefore, the
Total running time for the merging is O(n lg (nfk)).
c) In training, It should be chosen such that it minimize the running time of the
joint algorithm.
If you assign the numeral of data to x-axis and the consumed time to y-axis,
You can draw (3'l -xlgx and (1'34:2 graphs. There should be an intersection
Point resolute by Cl and Cg, which represent the data number that the
Merge sort is rstly sooner than insertion sort. So, it is natural to choose the 1:-
Value of the connection point as kl: is well known that the insertion sort is the
highest one when n S 16, so we could say in is 16 experimentally
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.