Trial and error is a problem-solving technique: try one approach, learn from its outcome, and try something different until you succeed. The process may require many attempts and is often guided by rewards or penalties. section 10.2
The technique works well when possible actions can be tested and their results observed. It connects naturally to reinforcement learning, where feedback encourages useful behavior and discourages harmful behavior. section 10.2 section 2.3
Finding a path through a maze
Imagine a 10-by-10 maze with barriers and a goal. Try paths by moving north, south, east, or west, then record whether each attempt reaches the goal and how many actions it takes. One attempt fails after four actions; four others succeed in 17, 23, 17, and 15 actions. The 15-action path is best among the attempts, although it was found by chance. A much larger maze makes manual trial and error exhausting, which motivates using search algorithms. section 2.3
The feedback loop can shape behavior in several ways:
- Reward a desirable action, such as giving a dog a treat after it sits. section 10.2
- Penalize an undesirable action, such as scolding a dog after it tears up a carpet. section 10.2
- Improve future choices as experience reveals which actions lead to food, shorter digging time, or other desired outcomes. section 10.2

