Loading workspace…
Loading workspace…
Representative code, explicit examples and transparent output.
1function binarySearch(values, target) {2 let lo = 0, hi = values.length - 1;3 while (lo <= hi) {4 const mid = Math.floor((lo + hi) / 2);5 if (values[mid] === target) return mid;6 if (values[mid] < target) lo = mid + 1;7 else hi = mid - 1;8 }9 return -1;10}11console.log(binarySearch([3, 8, 12, 17, 24], 17));The built-in binary-search implementation runs on bounded input data. Edited text is never evaluated.
O(log n) time, O(1) algorithm space; the educational trace is stored separately.