Class SequentialSearch

java.lang.Object
topics.divideconquer.SequentialSearch

public class SequentialSearch extends Object
DIVIDE AND CONQUER PROBLEM: CALCULATE THE POSITION OF AN ELEMENT x IN A VECTOR (SORTED OR UNSORTED) OF n DIFFERENT ELEMENTS
Author:
vicegd
  • Constructor Details

    • SequentialSearch

      public SequentialSearch()
  • Method Details

    • sequentialSearch1

      public int sequentialSearch1(int[] v, int x)
      This method iteratively calculates the position of x in the vector. It is O(n)
      Parameters:
      v - Array with numbers
      x - Value that is being searched
      Returns:
      The position of the value x in v
    • sequentialSearch2

      public int sequentialSearch2(int[] v, int x)
      This method recursively calculates the position of x in a vector. DandC by subtraction with a=1,b=1,k=0 - O(n)
      Parameters:
      v - Array with numbers
      x - Value that is being searched
      Returns:
      The position of the value x in v