Question: binary_search(s, i, j, key) { if (i>j) return 0 k = (i + j)/2 if(key == s_k) return k k1 = binary_search2(s, i, k-1, key)
binary_search(s, i, j, key) {
if (i>j)
return 0
k = (i + j)/2
if(key == s_k)
return k
k1 = binary_search2(s, i, k-1, key)
k2 = binary_search2(s, k+1, j, key)
return k1 + k2
}
(a). Show that binary_search2 is correct; that is, if key is present, the algorithm returns its index, but if keys is not present, it returns 0.
(b). Find the worst-case running time of binary_search2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
