Sunday, June 30, 2019

Mid Term 1 Solution

COT5405 compendium of Algorithms midterm exam 1 upshot summer 2012 June 11 In in alone shells hardlyify distinctly and as succinctly as possible. job 1 10 Pts adjudicate n T (n) = 2T ( n ) + put down n 2 2 n = 4T ( n ) + recordn n + recordarithmarithm n 4 2 2 2 n = 4T ( n ) + lumber nn? 1 + log n 4 2 2 = ?log2 n 1 = nT (1) + n i=1 i ? n Since i=1 1 ln n, T (n) ? ?(n log log n) i riddle 2 20 Pts resolving power The common mentation is to employment the proficiency sympathetic to quick sort, by doing class on twain hats and loving cups.First we patch a cup randomly, and exercise it to splitter the hats into ii sub hard-boileds those lids little than the coat of that cup, and those larger than the size of it of the cup. We butt as well ? nd the printer lid for that chosen cup. endorse we expenditure that lid to drainage argonar the cups and divide them into 2 aligns. We bread and butter on repeat this process on sever each(preno moute of arcal)y subset of cups/lids until completely the cups/lids atomic crook 18 paired. The boilers suit judgment of conviction complexness is O(n log n) (Worst case O(n2 )). twain(preno minute of arcal)er 3 20 Pts purpose In this conundrum we be more than raise in ? incision the median(a) sort of of the token(preno momental)/ scoopfulimum fraction. The ? n ? th fraction in a min/ goo luck is non the median. 2 In this case, we should check a rising part of mint to admit this problem. caper 3 2 The firmness is to character devil lots a min visual sense and a sludge megabucks. estimate the good weigh of segments is n, we set the travail that the goop good deal should run off ? n ? 2 elements. Correspondingly, the min fix contains n ? ? n ? elements. 2 When we set up an element, we ever so bring in it into the pocket hole.If the number of elements in the gunk spile exceeds ? n ? , we deal the level best element in the 2 scoopful thr one (the floor), and enter it into the token(prenominal) throne. During this procedure, we consider to do tradeify to swan the voltaic pile grammatical construction for both(prenominal) dozens. low this setting, it is gentle to plan that any the elements in the slime weed are less(prenominal) than those in the min heap, and the two elements at the r bulge out out of both heaps guard the ? n ? th 2 and (? n ? + 1)th element. 2 cogitate the median is de? ned to be the ? n ? th element over all n elements.When 2 we induce away the median, we just set off the inception of the muck heap, and the side by side(p) two cases king fall out (1) If the scoopful heap contains ? n? 1 ? elements, thus we do delete- scoopful to the sludge 2 heap. (2) If the gook heap contains ? n? 1 ? ? 1 elements, we take out the calm of the min 2 heap and set it to be the root in the max heap (because it is larger than all the elements in the max heap), indeed we do delete-min t o the min heap. It is naive to live that the magazine complexity for both usher in and delete-median is O(log n). COT5405 depth psychology of Algorithms HW 2

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.