12.27 LAB: Binary search generic method Implement the Searcher class's binarySearch() generic method in the Searcher.java file. Access Searcher.java by clicking on the orange arrow next to BinarySearch.java at the top of the coding window. The method performs a binary search on the sorted array (first parameter) for the key (third parameter). binarySearch () returns the key's index if found, -1 if not found. Compare an array element to the key using the compare ( ) method of the comparer object passed as binary Search ()'s last parameter. comparer.compare(a, b) returns an integer: • greater than 0 if a > b • less than 0 if a

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Question

Write the full Java code for Searcher.java

12.27 LAB: Binary search generic method
Implement the Searcher class's binarySearch() generic method in the Searcher.java file. Access Searcher.java by clicking on the orange
arrow next to BinarySearch.java at the top of the coding window. The method performs a binary search on the sorted array (first parameter)
for the key (third parameter). binarySearch () returns the key's index if found, -1 if not found.
Compare an array element to the key using the compare ( ) method of the comparer object passed as binary Search ()'s last
parameter. comparer.compare(a, b) returns an integer:
•
greater than 0 if a > b
• less than 0 if a<b
•
equal to 0 if a == b
A few test cases exist in the main method 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 the main method 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 binarySearch( )'s return value and the number of comparisons
performed.
Transcribed Image Text:12.27 LAB: Binary search generic method Implement the Searcher class's binarySearch() generic method in the Searcher.java file. Access Searcher.java by clicking on the orange arrow next to BinarySearch.java at the top of the coding window. The method performs a binary search on the sorted array (first parameter) for the key (third parameter). binarySearch () returns the key's index if found, -1 if not found. Compare an array element to the key using the compare ( ) method of the comparer object passed as binary Search ()'s last parameter. comparer.compare(a, b) returns an integer: • greater than 0 if a > b • less than 0 if a<b • equal to 0 if a == b A few test cases exist in the main method 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 the main method 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 binarySearch( )'s return value and the number of comparisons performed.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education