Javascript Binary Search/Insertion Preformance

前端 未结 2 1288
灰色年华
灰色年华 2021-01-17 06:48
function binarySearch(value)
{
    var startIndex = 0,
        stopIndex = words.length - 1,
        middle = Math.floor((stopIndex + startIndex) / 2);

    while (w         


        
2条回答
  •  难免孤独
    2021-01-17 07:17

    The best way is to use trees instead, since for an array such an operation is likely to have linear algorithmic complexity.

    If you'd like to stick with the arrays, I suggest that you use the splice method for insertion.

提交回复
热议问题