Sequential table lookup algorithm is the most basic searching technique in the algorithm.
Algorithm principle: In layman's terms, look up data from a table and return the current value index whenever you see the same data as the value you are taking.
On the code:
public int seqserch (int []a, int key) {
int i,n=a.length;
for (i = 1; i < n; i++) {
if (a[i] = = key) {
return i;
}}
}
The code is simple, but when multiple threads or concurrent requests are encountered, the value of I may be out of bounds. So, the program community has a
Well-known Sentinel mode, here is the rewritten code:
public int Seq_serch (int []a, int key) {
int i;
A[0] = key;//Sentinel
i = a.length//starts from the tail
while (a[i]! = key) {
i--;
}
Return i;//if return 0 fails to find
}
Summary: Sequential lookup technology is extremely inefficient when it encounters a very large range of lookups. Sentinel mode is recommended when there is a small amount of data available.