A* search algorithm
The computer goes on and finds the fastest way to get to E. Finally, it goes from D to Z, and finds a cost, and from E to Z and finds a cost. It gets a final cost for Z, and this is the smallest cost it can get. Now the computer knows which way is the fastest, and it has the answer. The computer can do a similar series of steps, but with many many more places. Each time, it will look at the place that's nearest to A, and will add up the costs to that place's neighbors.