Package com.zybooks.dsaj.recursion
Class BinarySearch
java.lang.Object
com.zybooks.dsaj.recursion.BinarySearch
Simple demonstration of the binary search algorithm.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
binarySearch
(int[] data, int target) Returns true if the target value is found in the data array.static boolean
binarySearch
(int[] data, int target, int low, int high) Returns true if the target value is found in the indicated portion of the data array.static boolean
binarySearchIterative
(int[] data, int target) Returns true if the target value is found in the data array.static void
Simple test, assuming valid integer given as command-line argument
-
Constructor Details
-
BinarySearch
public BinarySearch()
-
-
Method Details
-
binarySearch
public static boolean binarySearch(int[] data, int target, int low, int high) Returns true if the target value is found in the indicated portion of the data array. This search only considers the array portion from data[low] to data[high] inclusive.- Parameters:
data
- sorted array of integerstarget
- the query valuelow
- the index of the left end of the search rangehigh
- the index of the right end of the search range- Returns:
- true if the target is found, false otherwise
-
binarySearch
public static boolean binarySearch(int[] data, int target) Returns true if the target value is found in the data array.- Parameters:
data
- sorted array of integerstarget
- the query value- Returns:
- true if the target is found, false otherwise
-
binarySearchIterative
public static boolean binarySearchIterative(int[] data, int target) Returns true if the target value is found in the data array.- Parameters:
data
- sorted array of integerstarget
- the query value- Returns:
- true if the target is found, false otherwise
-
main
Simple test, assuming valid integer given as command-line argument
-