Click or drag to resize
BinarySearch Class

The BinarySearch class provides a static method for binary searching for an integer in a sorted array of integers.

The Rank operations takes logarithmic time in the worst case.

Inheritance Hierarchy
SystemObject
  Algs4NetBinarySearch

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class BinarySearch

The BinarySearch type exposes the following members.

Methods
  NameDescription
Public methodStatic memberIndexOf
Returns the index of the specified key in the specified array.
Public methodStatic memberMainTest

Demo test for the BinarySearch data type.

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.

Public methodStatic memberRank
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.
Top
Remarks
For additional documentation, see Section 1.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class BinarySearch implementation by Robert Sedgewick and Kevin Wayne.

See Also