Class Search

java.lang.Object
topics.foundation.search.Search

public class Search extends Object

Search (Algorithmic Structural Variations)

Provides a comparative implementation of fundamental search algorithms (Sequential, Sentinel, and Binary) to demonstrate their operational mechanics and algorithmic complexities.

Author:
vicegd
  • Constructor Details

    • Search

      public Search()
  • Method Details

    • searchSequential

      public boolean searchSequential(int[] list, int value)
      Performs a standard sequential (linear) search across an array.

      Complexity: O(N) Time | O(1) Space. Evaluates every element sequentially until a match is found or the boundaries are exhausted.

      Parameters:
      list - The array of integers to be searched.
      value - The target integer to locate.
      Returns:
      true if the element exists within the array, false otherwise.
    • searchSequentialSentinel

      public boolean searchSequentialSentinel(List<Integer> list, int value)
      Performs a sequential search utilizing a "sentinel" value.

      Mechanics: Temporarily appends the target value to the end of the list. This guarantees the search will find the element, eliminating the need to check array boundaries (i < length) during the inner loop, which can yield slight micro-optimizations in continuous memory blocks.

      Complexity: O(N) Time | O(1) Amortized Space.

      Parameters:
      list - The dynamically resizable list of integers.
      value - The target integer to locate.
      Returns:
      true if the element existed before the sentinel was added.
    • searchBinary

      public boolean searchBinary(int[] list, int value)
      Performs a binary search across a strictly sorted array.

      Mechanics: Halves the search space on each iteration by comparing the target value against the central pivot. Note: The input array must be sorted prior to execution.

      Complexity: O(log N) Time | O(1) Space.

      Parameters:
      list - The sorted array of integers.
      value - The target integer to locate.
      Returns:
      true if the element is found, false otherwise.