CHAPTER 10: SEARCHING ALGORITHMS
10.1 LINEAR SEARCH
10.1.1 How It Works
- Start at first element
- Compare with target
- If match, return position
- If not, move to next element
- Repeat until found or end of list
10.1.2 Pseudocode
<PSEUDOCODE>
10.1.3 Python Code
<PYTHON>
10.1.4 Complexity
- Time: O(n)
- Space: O(1)
10.2 BINARY SEARCH
10.2.1 Prerequisites
- List MUST be sorted
10.2.2 How It Works
- Find middle element
- Compare with target
- If match, return position
- If target > middle, search right half
- If target < middle, search left half
- Repeat until found or sublist empty
10.2.3 Pseudocode
<PSEUDOCODE>
10.2.4 Python Code
<PYTHON>
10.2.5 Complexity
- Time: O(log n)
- Space: O(1)