Documentation of 'edu.princeton.cs.algs4.BinarySearch' Java class
BinarySearch
edu.princeton.cs.algs4

Class BinarySearch



  • public class BinarySearch
    extends java.lang.Object
    The BinarySearch class provides a static method for binary searching for an integer in a sorted array of integers.

    The indexOf operations takes logarithmic time in the worst case.

    For additional documentation, see Section 1.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method and Description
      static int indexOf(int[] a, int key)
      Returns the index of the specified key in the specified array.
      static void main(java.lang.String[] args)
      Reads in a sequence of integers from the whitelist file, specified as a command-line argument; reads in integers from standard input; prints to standard output those integers that do not appear in the file.
      static int rank(int key, int[] a)
      Deprecated. 
      Replaced by indexOf(int[], int).
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • indexOf

        public static int indexOf(int[] a,
                                  int key)
        Returns the index of the specified key in the specified array.
        Parameters:
        a - the array of integers, must be sorted in ascending order
        key - the search key
        Returns:
        index of key in array a if present; -1 otherwise
      • rank

        @Deprecated
        public static int rank(int key,
                                           int[] a)
        Deprecated. Replaced by indexOf(int[], int).
        Returns the index of the specified key in the specified array. This function is poorly named because it does not give the rank if the array has duplicate keys or if the key is not in the array.
        Parameters:
        key - the search key
        a - the array of integers, must be sorted in ascending order
        Returns:
        index of key in array a if present; -1 otherwise
      • main

        public static void main(java.lang.String[] args)
        Reads in a sequence of integers from the whitelist file, specified as a command-line argument; reads in integers from standard input; prints to standard output those integers that do not appear in the file.
        Parameters:
        args - the command-line arguments

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.