Finding the shortest route — Computing, 7–10
Computers can compare possible routes through streets, rooms or game maps. The important idea is that a good route needs a clear measure, such as distance or time.
A route is a choice
To get from one place to another, there may be several possible routes. A computer can represent each route as connected steps and add their costs. The cost might be the number of squares, kilometres, minutes or coins. It then looks for a route whose total cost is smaller than the others.
Why compare routes?
People first needed route-finding for maps, deliveries and journeys, but checking every possible path takes too long in a large place. Computers are good at repeating careful comparisons without getting tired. The problem is not merely finding a route; it is finding one that saves distance, time, fuel or money.
Three paths on a map
You need to move from A to B. Route 1 has 4 squares, route 2 has 3 squares, and route 3 has 5 squares. If every square costs one point, their totals are 4, 3 and 5. The computer chooses route 2 because 3 is the smallest total. If mud made one square cost 3 points, it would need to add those new costs instead.
Shortest is not always fastest
It feels natural to choose the route with fewer steps, so people often call it the best route. But a short road can be crowded, steep or closed, while a longer road may be quick. The computer cannot guess what best means: you must tell it whether to count distance, time, danger, price or something else.
Routes in real life
Map apps use route-finding to suggest journeys, and delivery systems use it to plan several stops. Games use similar ideas to move a character around obstacles. The result depends on the map and the costs it receives, so a route can be mathematically best while still being unsuitable for a person.
Keep exploring
Other languages
Loading MyLeoNes™…