Monday, August 24, 2020

Mid Term 1 Solution Free Essays

COT5405 Analysis of Algorithms Midterm 1 Solution Summer 2012 June 11 In all cases clarify unmistakably and as compactly as could reasonably be expected. Issue 1 10 Pts Answer: n T (n) = 2T ( n ) + log n 2 n = 4T ( n ) + logn n + log n 4 2 n = 4T ( n ) + log nn? 1 + log n 4 2 = †¦ ?log2 n 1 = nT (1) + n i=1 I ? n Since i=1 1 ln n, T (n) ? ?(n log n) I Problem 2 20 Pts Answer: The general thought is to utilize the procedure like snappy sort, by doing allotment on the two tops and cups. First we pick a cup arbitrarily, and use it to segment the covers into two subsets: those covers littler than the size of that cup, and those bigger than the size of the cup. We will compose a custom paper test on Mid Term 1 Solution or on the other hand any comparative point just for you Request Now We can likewise ? nd the journalist cover for that picked cup. Second we utilize that top to segment the cups and partition them into two sets. We continue rehashing this method on every subset of cups/tops until all the cups/covers are combined. The general time unpredictability is O(n log n) (Worst case: O(n2 )). Issue 3 20 Pts Answer: In this difficult we are increasingly keen on ? ding the middle rather than the base/most extreme component. The ? n ? th component in a min/max stack isn't the middle. 2 For this situation, we ought to build up another sort of store to adjust this issue. Issue 3 2 The arrangement is to utilize two piles: a min stack and a maximum pile. Assume the all out number of components is n, we set the limitation that the maximum load ought to contain ? n ? 2 components. Correspondingly, the min load contains n ? ? n ? components. 2 When we embed a component, we generally embed it into the maximum pile. On the off chance that the quantity of components in the maximum stack surpasses ? n ? , we evacuate the greatest component in the 2 max load (the root), and addition it into the base store. During this system, we have to do heapify to keep up the load structure for the two stacks. Under this setting, it is anything but difficult to see that all the components in the maximum load are not exactly those in the min store, and the two components at the foundation of the two piles speak to the ? n ? th 2 and (? n ? + 1)th component. 2 Suppose the middle is de? ned to be the ? n ? th component over all n components. At the point when 2 we erase the middle, we simply erase the foundation of the maximum store, and the accompanying two cases may happen: (1) If the maximum pile contains ? n? 1 ? components, at that point we do erase max to the maximum 2 pile. (2) If the maximum load contains ? n? 1 ? ? 1 components, we take out the foundation of the min 2 store and set it to be the root in the maximum stack (since it is bigger than all the components in the maximum pile), at that point we do erase min to the min pile. It is clear to see that the time unpredictability for both embed and erase middle is O(log n). COT5405 Analysis of Algorithms HW 2 Instructions to refer to Mid Term 1 Solution, Essay models

No comments:

Post a Comment

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