Javascript implements the binary search method. Generally, binary code is used in 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, it seems that the amount of code is not small.
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. I just want to give a thought. Next time I will send a js solution to the eight queens problem. The algorithm is amazing.
The Code is as follows:
Var array = [];
Var key = 482;
Var number = 1000;
For (I = 0; I Array. push (I );
}
// -->
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 <array [center]) {
Right = center-1;
} Else {
Left = center + 1;
}
}
Alert ("result of the Binary Search Method:" + );
Alibaba (new Date ()-time)/1000 );