Chapter 2
Searching Algorithms
IN THIS CHAPTER
Conducting sequential searches
Using an index
Doing an adversarial search
One of the most common functions of a computer program is searching. A database needs to search through names and addresses, a word processor needs to search through text, and even a computer chess game needs to search through a library of moves to find the best one.
Because searching is such an important part of computer programming, computer scientists have developed a variety of algorithms to search for data. When searching for data, the main limitation is time. Given enough time, any search algorithm can find what you want, but there’s a big difference between finding data in five seconds and finding it in five hours.
The time a search algorithm takes is always related to the amount of data to search, which is the search space. The larger the search space, the longer the search algorithm takes. If you only need to search a small search space, even a simple and slow search algorithm can be fast enough.
The two main categories of search algorithms are
- Uninformed (brute-force): Uninformed, or brute-force, search algorithms work by simply examining the entire ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access