Question: 4 . 1 1 LAB: Binary search with custom comparer Implement the Searcher class's binary _ search ( ) method in the Searcher.py file. Access
LAB: Binary search with custom comparer
Implement the Searcher class's binarysearch method in the Searcher.py file. Access Searcher.py by clicking on the orange arrow next to main.py at the top of the coding window. The method performs a binary search on the sorted list second parameter for the key third parameter binarysearch returns the key's index if found, if not found.
Compare a list element to the key using the compare method of the comparer object passed as a parameter of the Searcher's constructor. comparer.comparea b returns an integer:
greater than if a b
less than if a b
equal to if a b
A few test cases exist in main to test binarysearch with both string searches and integer searches. Clicking "Run program" will display test case results, each starting with "PASS" or "FAIL". Ensure that all tests are passing before submitting code.
Each test in main only checks that binarysearch returns the correct result, but does not check the number of comparisons performed. The unit tests in the submit mode check both binarysearchs return value and the number of comparisons performed.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
