Class Search
java.lang.Object
topics.introduction.Search
To use different methods for searching numbers in an array
- Author:
- vicegd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleansearchBinary(int[] list, int value) Performs a binary search in an array, reducing the complexity when the number is not there: O(nlogn)booleansearchSequential(int[] list, int value) Performs a sequential search in an arraybooleansearchSequentialSentinel(List<Integer> list, int value) Performs a sequential search in an array using a sentinel to avoid checking if we are inside the limits of the array
-
Constructor Details
-
Search
public Search()
-
-
Method Details
-
searchSequential
public boolean searchSequential(int[] list, int value) Performs a sequential search in an array- Parameters:
list- Array with numbersvalue- Value to be found in the array- Returns:
- True if the element was found, false otherwise
-
searchSequentialSentinel
Performs a sequential search in an array using a sentinel to avoid checking if we are inside the limits of the array- Parameters:
list- Array with numbersvalue- Value to be found in the array- Returns:
- True if the element was found, false otherwise
-
searchBinary
public boolean searchBinary(int[] list, int value) Performs a binary search in an array, reducing the complexity when the number is not there: O(nlogn)- Parameters:
list- Array with numbersvalue- Value to be found in the array- Returns:
- True if the element was found, false otherwise
-