Linear and Binary Search
When to Use Which
| Use Linear Search | Use Binary Search | |---|---| | Unsorted data | Sorted data | | Small arrays (< ~20 elements) | Large arrays | | Single search (sorting + binary is overkill) | Multiple searches (amortize sort cost) | | Linked lists (no random access) | Random-access structures (arrays) |
Complexity
| | Linear | Binary | |---|---|---| | Best | O(1) | O(1) | | Average/Worst | O(n) | O(log n) | | Space (iterative) | O(1) | O(1) | | Prereq
[Description truncada. Veja o README completo no GitHub.]