Ricerca
Guarda la ricerca lineare e binaria cercare un valore passo dopo passo: confronti, dimezzamenti e risultati trovato/non trovato.
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.
Confronto: Ricerca
| Algoritmo | Migliore | Medio | Peggiore | Spazio | Dati ordinati richiesti? |
|---|---|---|---|---|---|
| Linear Search | O(1) | O(n) | O(n) | O(1) | No |
| Binary Search | O(1) | O(log n) | O(log n) | O(1) | Yes |