edu.princeton.cs.algs4
Class BinarySearch
- java.lang.Object
-
- edu.princeton.cs.algs4.BinarySearch
-
public class BinarySearch extends java.lang.ObjectTheBinarySearchclass 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 intindexOf(int[] a, int key)Returns the index of the specified key in the specified array.static voidmain(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 intrank(int key, int[] a)Deprecated.Replaced byindexOf(int[], int).
-
-
-
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 orderkey- the search key- Returns:
- index of key in array
aif present;-1otherwise
-
rank
@Deprecated public static int rank(int key, int[] a)Deprecated. Replaced byindexOf(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 keya- the array of integers, must be sorted in ascending order- Returns:
- index of key in array
aif present;-1otherwise
-
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