Generally, binary data is used on Int ..... in JS, A-Z may be used more flexibly, or pinyin may be used... or ......
However, it is worth pondering whether the following process is worthwhile to achieve binary search such as pinyin:
1. Sorting pinyin, looks likeCodeA large volume.
2. Then, perform a secondary search. In this case, we need to identify the size of Pinyin. It seems that it is not too small.
The speed of finding the results is faster, but the speed of your JS files is much slower.
The following code can even be found as soon as 1 billion, but the array is created in the example mode... So stop trying. Just give me a thought. Next time I will send a JS solution to the eight queens problem.AlgorithmWonderful.
Copy codeThe Code is as follows: var array = [];
Var key = 482;
VaR number = 1000;
for (I = 0; I array. push (I);
}< br> // -->
var time = new date ();
var;
var left = 0;
var right = array. length;
while (left <= right) {
var center = math. floor (left + right)/2);
If (array [center] = Key) A = center;
If (Key right = center-1;
}else {
left = center + 1;
}< BR >}< br> alert ("binary search result:" + a);
alert (new date ()-Time) /1000);