Study smarter with Fiveable
Get study guides, practice questions, and cheatsheets for all your subjects. Join 500,000+ students with a 96% pass rate.
Search algorithms form the backbone of nearly every program you'll encounter—from finding a contact in your phone to GPS navigation plotting your route. In this course, you're being tested on your ability to analyze time complexity, space complexity, and algorithmic trade-offs. Understanding search algorithms means understanding how computer scientists solve the fundamental problem of locating data efficiently, and why choosing the wrong algorithm can mean the difference between milliseconds and hours of computation.
Don't just memorize that binary search is —know why it achieves that complexity through interval halving, when it applies (sorted data only), and how it compares to alternatives. Exam questions will ask you to select the right algorithm for a scenario, analyze worst-case performance, or trace through an algorithm's execution. Master the underlying mechanisms, and you'll handle any variation they throw at you.
These algorithms work directly on arrays or lists, moving through elements in predictable patterns. The key distinction is whether they require sorted data and how they reduce the search space.
Compare: Linear Search vs. Binary Search—both find a target in an array, but linear works on unsorted data at while binary requires sorting but achieves . If an FRQ gives you a sorted array and asks for the most efficient search, binary search is always your answer.
These algorithms improve on binary search for specific data distributions or unknown dataset sizes. They exploit mathematical properties of the data to make smarter guesses about target location.
Compare: Binary Search vs. Interpolation Search—both require sorted data and achieve sub-linear time, but interpolation makes position estimates based on value (like humans searching a dictionary) while binary always splits in half. Use interpolation only when you can guarantee uniform distribution.
These algorithms navigate nodes and edges rather than array indices. The fundamental choice is between exploring deep (DFS) or wide (BFS), which determines what kind of solution you find first.
Compare: DFS vs. BFS—same time complexity , but DFS uses a stack and finds a path while BFS uses a queue and finds the shortest path in unweighted graphs. When an exam asks about shortest path without edge weights, BFS is correct; when it asks about exploring all possibilities or detecting cycles, think DFS.
These algorithms use domain knowledge to make intelligent choices about which paths to explore. Heuristics transform brute-force search into informed decision-making.
Compare: BFS vs. A* Search—both can find shortest paths, but BFS explores blindly in all directions while A* uses a heuristic to prioritize promising paths. For weighted graphs or large search spaces, A* dramatically outperforms BFS when you have a good heuristic.
| Concept | Best Examples |
|---|---|
| Unsorted data search | Linear Search |
| Sorted array search | Binary Search, Jump Search |
| Uniformly distributed data | Interpolation Search |
| Unknown dataset size | Exponential Search |
| Unweighted shortest path | BFS |
| Graph traversal/cycle detection | DFS |
| Weighted shortest path with heuristic | A* Search |
| complexity | Binary Search, Exponential Search |
Which two search algorithms both require sorted data but use different strategies to estimate target position? How do their best-case complexities compare?
You need to find the shortest path between two nodes in an unweighted graph. Which algorithm guarantees the optimal solution, and what data structure does it use?
Compare DFS and BFS: they share the same time complexity, so what factors should determine which one you choose for a given problem?
An FRQ presents a scenario where you must search an infinitely long sorted stream of data. Which algorithm is designed for this situation, and why does it outperform standard binary search here?
Explain why A* search can outperform BFS on weighted graphs. What property must the heuristic function have to guarantee A* finds the optimal path?