Unformatted text preview: A and B are distinct, and 1 ≤ k ≤ n + hilo + 1 4 if lo = hi + 1 then 5 return 6 else 7 mid ← ± lo + hi 2 ² 8 use a binary search of B [1 ..n ] to ﬁnd the number of elements m in 9 B that are less than A [ mid ] 10 if then 11 return A [ mid ] 12 else if then 13 return Select ( mid + 1 ,hi, ) 14 else 15 return Select ( lo,mid1 , ) 16 end if 17 end if 18 Postcondition: returns the k th smallest element in 19 { A [ j ] : lo ≤ j ≤ hi } ∪ { B [ j ] : 1 ≤ j ≤ n } 20 end Select (c) Using bigΘ notation, state the worstcase running time of the algorithm in part (b) in terms of lo,hi,n and/or k . Explain why your answer is correct. (d) To solve the original problem, you would call Select (1 ,n,k ). Using bigΘ notation, state the worstcase running time of this call in terms of n and/or k . Explain why your answer is correct. 1...
View
Full Document
 Winter '16
 Algorithms, Sort, Analysis of algorithms, Lo, kth smallest element

Click to edit the document details