Class BinarySearch

java.lang.Object
com.zybooks.dsaj.recursion.BinarySearch

public class BinarySearch extends Object
Simple demonstration of the binary search algorithm.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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
    main(String[] args)
    Simple test, assuming valid integer given as command-line argument

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 integers
      target - the query value
      low - the index of the left end of the search range
      high - 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 integers
      target - 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 integers
      target - the query value
      Returns:
      true if the target is found, false otherwise
    • main

      public static void main(String[] args)
      Simple test, assuming valid integer given as command-line argument