I have two arrays (one going from 0-49 listing every US state, and another one going from 0-49 listing the US capitals.) and I need to binary search the second array to match a selected US state to capital. How do I do that?
Here's the code I've got. I should return State Capital + number of probes.
public static int BinarySearch(String key, String[] a) {
int lo = 0;
int hi = a.length - 1;
int mid = 0;
String stateinarray = "";
NumberofProbes = 0;
// YOUR CODE GOES HERE
YOUR CODE GOES HERE, not ours! So do your part, and then when you get stuck, come back and ask about where you get stuck. Stackoverflow is not a code-writing service.binarySearch()method. 3) The use case you're describing should be addressed with aMap, not two arrays. 4) Tell whoever gave you that assignment to learn proper Java naming conventions.BinarySearchneeds to search forkeyina? That method returns anint, so should the method return the index ofkeyinaor -1 (negative one) ifkeyis not found ina?