This article illustrates the application of C + + binary search in multiple document intersection of search engines. Share to everyone for your reference. Specifically as follows:
int search2 (int array[], int n, int v)
{
int left, right, middle;
left = 0, right = n-1;
While [left <= right]
{
middle = (left + right)/2;
if (Array[middle] > V)
{right
= middle-1;
}
else if (Array[middle] < V)
{left
= middle + 1;
}
else
{return
middle;
}
}
return-1;
}
int Search3 (int array[], int n, int v)
{
int left, right, middle;
left = 0, right = N;
While [left < right]
{
middle = (left + right)/2;
if (Array[middle] > V)
{right
= middle;
}
else if (Array[middle] < V)
{left
= middle + 1;
}
else
{return
middle;
}
}
return-1;
}
The algorithm complexity of binary lookup is log2n, and it is an efficient search.
In search, will use the document intersection, for example a user's retrieval, from each cluster on the Internet spit data, these documents may be intersection, and provide the data is orderly, how to get intersection document?
This allows you to use a binary lookup, in multiple ordered document arrays, to pick a shortest one, and then pick one element at a time, and then double-click in the other array to get the Intersect document.
I hope this article will help you with the C + + program design.