探索
線形探索と二分探索がターゲット値を段階的に見つける様子を観察:比較、半分に絞り込み、ヒット/ミスの結果。
Linear SearchScan the array one element at a time until the target appears.Binary SearchHalve the search window each step until the target is found.
探索の比較
| アルゴリズム | 最良 | 平均 | 最悪 | 空間 | ソート済みが必要? |
|---|---|---|---|---|---|
| Linear Search | O(1) | O(n) | O(n) | O(1) | No |
| Binary Search | O(1) | O(log n) | O(log n) | O(1) | Yes |