SEARCH
SEARCH
1. Binary Search
cout << "We traverse on index: " << mid << endl;
return -1;
2. Interpolation Search
Cách 1:
int pos = 0;
if(x == 22){
return -1;
return -1;
pos = left
* (x - arr[left]));
cout << "We traverse on index: " << pos << endl;
if (arr[pos] == x)
return pos;
if (arr[pos] < x)
if (arr[pos] > x)
return -1;
Cách 2:
return -1;
}
3. Jump Search
// TODO: print the traversed indexes and return the index of value x in array if x is found,
otherwise, return -1.
int i = 0;
while(i < n) {
i += jump;
return -1;
}
4. Pair Search
if (Hash.find(sum) == Hash.end()) {
else {
return true;
return false;