Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions

Question

Explain how thinking of a response can hamper listening.

Answered: 1 week ago

Question

Organizing Your Speech Points

Answered: 1 week ago