You open a map app, type the name of your exam centre, and a second later a route appears. Between your home and that centre there are thousands of junctions and millions of ways to string them together. The app did not try them all. It did not even try a hundredth of them. Somewhere inside, a program looked at the roads, guessed which direction was promising, and walked there first. The same kind of program plays chess against you, finds a free slot for a class routine, and tunes the settings of a machine.
In the last chapter we met problems where the number of possibilities explodes and nobody knows a method that beats trying almost all of them: the travelling salesman, colouring a map, satisfying a logical formula. Does that mean we give up? No. We search, and we search cleverly. This chapter is the toolbox for that. It is the part of artificial intelligence that long predates today's neural networks, and the exams still ask it every year: breadth-first against depth-first, what A* is, why hill climbing gets stuck, what alpha-beta pruning saves.
By the end you will be able to describe any such problem as states, actions and a goal; run BFS, DFS, uniform-cost and iterative deepening by hand and count the nodes; run greedy search and A* and explain, with a proof sketch, why A* with an admissible heuristic finds the cheapest route; climb hills and cool metal (simulated annealing) on a landscape of numbers; run one generation of a genetic algorithm; play minimax and cut the tree with alpha-beta; and solve a constraint problem by backtracking with forward checking. Every table in this chapter comes from a program that actually ran.
We go in eight parts: how to state a search problem; blind search; heuristic search and A*; local search; genetic algorithms; games; constraint satisfaction; and finally how to choose and how to answer in the exam.