Class SequentialSearch
java.lang.Object
topics.divideconquer.SequentialSearch
DIVIDE AND CONQUER PROBLEM: CALCULATE THE POSITION OF AN ELEMENT x IN A
VECTOR (SORTED OR UNSORTED) OF n DIFFERENT ELEMENTS
- Author:
- vicegd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintsequentialSearch1(int[] v, int x) This method iteratively calculates the position of x in the vector.intsequentialSearch2(int[] v, int x) This method recursively calculates the position of x in a vector.
-
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 numbersx- 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 numbersx- Value that is being searched- Returns:
- The position of the value x in v
-