Question: 6 . ( 3 . 3 . 2 6 ) Recall that a binary search exploits the ordered nature of a sorted sequence. ( a

6.(3.3.26) Recall that a binary search exploits the ordered nature of a sorted sequence. (a) Consider the following recursive algorithm for searching a sorted sequence: TernarySearch(xA =(a0 a1 an 1)) Input: An integer x and a finite, non-empty, sorted sequence A of n integers Output: Whether or not x is an element of A 1: let i be n/3 and j be 2n/32: if ai = x or aj = x then 3: return T 4: else if n 2 then 5: return F 6: else if x < ai then 7: return TernarySearch(x(a0 a18: else if ai < x < aj then 9: return TernarySearch(x(ai ai+110: else 11: return TernarySearch(x(aj aj+1 ai 1)) aj 1)) an 1)) Set up and a solve a recurrence relation giving a Big-O estimate for the complexity of this algorithm. (b) Compared to a binary search, would any algorithm that attempted to divide the sequence into b >2 subsequences offer any further improvement in time complexity?

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 Programming Questions!