I\'m looking to optimize this linear search:
static int
linear (const int *arr, int n, int key)
{
int i = 0;
while (i < n) {
loop backwards, this might be translated...
// loop backward
for (int i = arraySize - 1; i >=0; --i)
...to this( "could be" faster ):
mov cx, arraySize - 1
detectionHere:
...
loop detectionHere
Other than that, only binary search can make searching faster
Well, you could use pointers...
static int linear(const int *array, int arraySize, int key) {
int i;
for(i = 0; i < arraySize; ++i) {
if(*array >= key) {
return i;
}
++array;
}
return arraySize;
}