Question: Hi how to do this in python Exercise 1 - Implement the Search Algorithms Implement linear search, binary search, and trinary search. The measure of

 Hi how to do this in python Exercise 1 - Implement

Hi how to do this in python

Exercise 1 - Implement the Search Algorithms Implement linear search, binary search, and trinary search. The measure of efficiency we will use in the remaining exercises is the number of times the search function is called. Once you know your search algorithms are working, modify the given algorithms to also return the total number of times the function is called during a search, in addition to the location of the search value. Hint The pseudocode for a recursive binary search is as follows: binary search (A, first, last, target): \# returns index of target in A, if present \# returns -1 if target is not present in A if first greater than last: return -1 else: mid= (first + last) /2 if A[mid] equals target: return mid else if A[mid] greater than target: return binary search(A, first, mid - 1, target) else: return binary search ( A, mid +1, last, target) Trinary search may be similarly implemented if we compute the values at 1/3 and 2/3 instead of the middle. Then, we check each of the conditions at 1/3 and 2/3 instead of just at the middle of the list

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!