hw4wu - time. A flip indicates a merge operation. So the...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
COT 6401 Analysis of Algorithms Homework #4 by Changfu Wu P.1/2 18-2 Making binary search dynamic [Solution] a. To perform search operation for this structure, we can just perform binary search for each of the sorted arrays till we find the data we are searching for. As we know, the time of the execution of the binary search algorithm on the array i A is ) ( ) 2 (lg i O O i = . Therefore, the worst-case running time of the dynamic binary search is - = = = - = 1 0 2 2 ) (lg ) ( )) 1 ( 2 1 ( ) ( k i n O k O k k O i O (  ) 1 lg( + = n k Q ) b. To insert a new element into this data structure, we just insert a new array 0 A into the arrays. If another 0 A exists, we merge these two 0 A into one 1 A . If another 1 A exists, we merge these two 1 A into one 2 A . We going on and keep merging till we do not need merge any longer. The worst case running time is ) ( 2 1 n O k i k = = (  ) 1 lg( + = n k ) For the amortized time, we can notice the binary representation of n , i.e., 0 2 1 , , , n n n k k L - - . When we perform a series of insertion, 0 n flips every time, 1 n flips every th 2 time, …, 1 - k n flips every th k 2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: time. A flip indicates a merge operation. So the total running time for m insertions is ∑-= + = ≤ ≤ 1 1 ) (lg 2 2 2 k i i i n mO mk m T So the amortized running time for each operation is ) (lg / ) (lg n O m n mO = . c. To delete an element, say x , in i A , first we find the smallest array that is not empty. Assume it is j A . Delete x from i A . If j i ≠ , take an element out of j A and insert it into i A . Whether j i ≠ or not, now the length of j A is 1 2-j . Then we divide array j A into j arrays, 1 1 , , ,-j A A A L , which are consistent with this data structure. COT 6401 Analysis of Algorithms Homework #4 by Changfu Wu P.2/2 5.22 [Solution] Algorithm: SELECTION( k n , ) 1 ] 1 [ Key candidate ← 2 for 2 ← i to 1 +-k n 3 if ] [ i Key candidate 4 ] [ i Key candidate ← 5 return candidate Number of comparisons: k n-Lower bound of comparisons: k n-...
View Full Document

This note was uploaded on 10/21/2011 for the course COT 6401 taught by Professor Staff during the Spring '09 term at FAU.

Page1 / 2

hw4wu - time. A flip indicates a merge operation. So the...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online