Question: Implement the Searcher class's ( binary _ search ( ) method in the Searcher.py file. The method performs a binary search on the sorted list

Implement the Searcher class's (binary_search() method in the
Searcher.py file. The method performs a binary search on the sorted list (second parameter) for the key (third parameter). binary_search() returns the key's index if found, -1 if not found.
Compare a list element to the key using the compare() method of the constructor retums an integer: object passed as a parameter of the Searcher's
greater than 0 if a>b
less than 0 if a==ba
equal to0ifa==b
A few test cases exist in main()to test with both string searches and integer searches. Running the program will display test case results, each starting with "PASS" or "FAIL": Ensure that all tests are passing before submitting code as shown below.
PASS: Search for key "Nectarine" returned -1.
PASS: Search for key "Mango" returned -1.
PASS: Search for key "Guava" returned 7.
PASS: Search for key "Strawberry" returned 15.
PASS: Search for key "Kiwi" returned -1.
PASS: Search for key "Apple" returned 0.
PASS: Search for key "Raspberry" returned 14.
PASS: Search for key "Carrot" returned -1.
PASS: Search for key "Lemon" returned 8.
PASS: Search for key "Bread" returned -1.
PASS: Search for key 42 returned 4.
PASS: Search for key 23 returned -1.
PASS: Search for key 11 returned 0.
PASS: Search for key 19 returned -1.
PASS: Search for key 87 returned -1.
PASS: Search for key 98 returned 12.
PASS: Search for key 66 returned -1.
PASS: Search for key 92 returned -1.
PASS: Search for key 1 returned -1.
PASS: Search for key 14 returned -1.
PASS: Search for key 21 returned 1.
PASS: Search for key 66 returned 6.
PASS: Search for key 87 returned -1.
PASS: Search for key 83 returned -1.
Each test in main() only checks that binary seareh() returns the correct result, but does not check the number of comparisons performed.
 Implement the Searcher class's (binary_search() method in the Searcher.py file. The

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!