How fast can you make linear search?

前端 未结 20 1916
死守一世寂寞
死守一世寂寞 2020-12-23 21:46

I\'m looking to optimize this linear search:

static int
linear (const int *arr, int n, int key)
{
        int i = 0;
        while (i < n) {
                      


        
20条回答
  •  无人及你
    2020-12-23 22:25

    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

提交回复
热议问题