public class SearchUtil
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
NOT_FOUND |
| Constructor and Description |
|---|
SearchUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends java.lang.Comparable<? super T>> |
binarySearch(java.util.List<T> l,
T x)
Search an object in an list of object using a binary search.
|
static <T extends java.lang.Comparable<? super T>> |
binarySearch(T[] a,
T x)
Search an object in an array of object using a binary search.
|
static int |
maxSubSum(int[] a)
Return the maximum sum of a consecutive sub sequence of the array
|
public static final int NOT_FOUND
public static <T extends java.lang.Comparable<? super T>> int binarySearch(T[] a,
T x)
Search an object in an array of object using a binary search.
Binary search is O(log N) complexity
The array must be sorted from lower to higher
a - the array to search inx - the object to search forpublic static <T extends java.lang.Comparable<? super T>> int binarySearch(java.util.List<T> l,
T x)
Search an object in an list of object using a binary search.
Binary search is O(log N) complexity
The list must be sorted from lower to higher
l - the list to search inx - the object to search forpublic static int maxSubSum(int[] a)
Return the maximum sum of a consecutive sub sequence of the array
For exemple, consider the following array : -2 11, -4, 13, -5, -2.
Then the maximum sub sequence sum is 20 (11, -4, 13).
a - an array of integers (positive and negatives)