Wren sorts the greenhouse seed packets alphabetically, then finds the basil packet in three quick looks.
"That was binary search," Comet says. "You started in the middle of the box."
Wren smiles. "Beacon's search does not care whether it is searching water readings or seed names."
Comet thinks about the rover. "And nearest-first could plan any trip with lots of stops."
Nova hovers between them. "I found a pattern," she says. "An algorithm is about steps, not about tomatoes."
"So one algorithm can help in many places," Wren says. "As long as the data fits what it needs."
An algorithm is a finite set of instructions that does a specific task. The steps do not depend on what the data is about.
Binary search works on any sorted data: numbers, names or dates. Only the sorting rule changes.
Nearest-first works on any trip with several stops, from a rover route to a day of errands.
Using existing correct algorithms as building blocks can reduce development time and testing, and makes errors easier to find.
| Week review | True or false? |
|---|---|
| A decision problem has a yes or no answer. | ? |
| Binary search needs sorted data. | ? |
| Efficiency can be measured informally by counting how many times statements run. | ? |
| Factorial growth runs in a reasonable amount of time. | ? |
| A heuristic is guaranteed to find the best solution. | ? |
Excellent week, developer. Tomorrow's Mission Quest is a guessing game for the whole family.