Class Search

java.lang.Object
topics.introduction.Search

public class Search extends Object
To use different methods for searching numbers in an array
Author:
vicegd
  • 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 numbers
      value - Value to be found in the array
      Returns:
      True if the element was found, false otherwise
    • searchSequentialSentinel

      public boolean searchSequentialSentinel(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
      Parameters:
      list - Array with numbers
      value - 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 numbers
      value - Value to be found in the array
      Returns:
      True if the element was found, false otherwise