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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!