Binary search
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
Binary search
The array is sorted. Return the index of target, or -1 if it isn't there. Binary search halves the range each step: check the middle element, then keep looking in just the left or right half. Far faster than scanning every element.
日本語
二分探索
この配列は整列済みです。targetのインデックスを返します。存在しない場合は-1を返します。二分探索では、各ステップで範囲を半分にし、中央の要素を確認した後に左または右の半分のみを探し続けます。すべての要素をスキャンするよりも遥かに高速です。
Complete binarySearch(int[] a, int target) for a sorted array a: return the index of target, or -1 if absent. Use binary search.
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。