A telephone directory having n = 10 records and Name field as key. Let us assume that the names are stored in array 'm' i.e. m(0) to m(9) and the search has to be made for name "X", i.e. element = "X".
Telephone Directory
Name id.
|
AA 25161234
|
BB 22752345
|
CC 23405678
|
DD 22361111
|
EE 24782202
|
FF 26254444
|
GG 26150880
|
HH 25513653
|
II 26252794
|
KK 26257149
|
The above algorithm will search for element = "GG" and will stop at 6th index of array and the needed id is "26150880", which is stored at position 7 i.e. 6+1.