Question: What is the runtime of the iterative version in terms of n, and why? Would it be something like O(log(n))? Why is that? Additionally, what

What is the runtime of the iterative version in terms of n, and why? Would it be something like O(log(n))? Why is that?

Additionally, what is the runtime of the RECURSIVE version in terms of n and why? Would it also be O(log(n))?

What would a recurrence relation look like for both? The code is below. Basically I was looking for how to calculate the run tme.

def binarySearch(alist, item): //ITERATIVE VERSION first = 0 last = len(alist)-1 found = False while first<=last and not found: midpoint = (first + last)/2 if alist[midpoint] == item: found = True else: if item < alist[midpoint]: last = midpoint-1 else: first = midpoint+1 return found def binarySearch(alist, item): //RECURSIVE VERSION if len(alist) == 0: return False else: midpoint = len(alist)/2 if alist[midpoint]==item: return True else: if item                        

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!