{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

InClassExercise22 - CS112 In-class Exercise 22 Binary...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS112: In-class Exercise 22 Binary Search 0 . Review of binary search. The array must be sorted, say in ascending order. Start with integer index variables bot set to 0 and top set to array length minus 1. Do a loop while bot <= top , o Calculate mid = (bot + top)/2; o Test whether the searched item equals the item at index mid . If yes, then item found, return index mid . o If not, then test whether the searched item is less than the item at index mid . If yes, then reset top to mid-1 . If no, then reset bot to mid+1 . If not found, return -1. 1. Copy the InClass22 folder from the usual locations. 2. Open the project using BlueJ. 3. Note that the Interactions class is all programmed and you don’t have to do anything to it. 4. Edit the source file for Algorithms . 5. Exercise A. Write the method for public static int linearSearch(String[] strings, String s) Note that the new keyword static means that this method can be called using the class name (namely, an Algorithms object is not needed).
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}