seegongsik
Saved words
Algorithms

Finding the fastest way

When you open a map for directions, the route with fewer turns isn't always the fast one. A short-looking road can be jammed and roundabout, so it ends up slower. Each road has its own distance. So how do we find the fastest way?

01

Each edge has its distance

You learned to link dot to dot with a line.
But roads have one more thing.
Each edge has a different distance.
Some roads are short,
some are far.
So we write a number on the line.
That number is the distance.
Below, tap a road to see its distance.

SABCDT
Tap a road to see its distance

Tap a road to see its distance. (Line = road · number = its distance)

Why does different distance matter?
Even a route through fewer turns,
if each hop is far,
can be slower overall.
The other way around, more turns
but each hop close,
can be faster overall.
So you can't choose a path without distance.

02

By nearness alone won't do

Earlier you saw spreading by nearness.
One hop, two hops, three hops,
counting how many hops from the start.
But that holds when every road
is the same single hop.
When edges have different distances,
the route with fewer hops
isn't always the nearer one.

SPXYT
Tap each route to compare

Tap both routes to compare. (Fewer hops vs shorter distance · not the same)

See? The route through fewer turns
was farther in distance.
Count hops only,
and you fall into this trap.
So we have to
add up distances,
not hops,
to find the truly nearer way.

03

Lock in the nearest first

So what do we do?
Recall picking the best in front of you.
Start from the start,
and among points whose distance isn't locked,
pick the one nearest right now
and lock its distance.
The nearest point
can't have any shorter way,
so locking it is safe.

2531264S0A2B5CDT
Tap the nearest unlocked point to lock it

Tap the nearest point to lock it. (Each round pick the shortest among unlocked)

This is picking the best in front.
Not solving the whole map at once,
but from the nearest point now,
locking them in one by one.
When you lock a point,
its neighbors reached through it
can get a new,
closer distance too.

04

Widen the boundary

As locked points grow,
a region of settled distances forms.
The edge of that region is the boundary.
Each time, just outside the boundary,
pull in the one nearest point,
and the region grows by a point.
Like dropping a stone in still water
and the ripple spreading out.

SABCDT
Tap a point just outside the boundary to grow the region

Tap a point past the boundary to grow the region. (Locked region grows outward one point at a time)

As the boundary keeps spreading out,
sooner or later every point
comes inside the locked region.
By then, from the start
to any point at all,
you know the fastest distance
for every one.
Nearest first, step by step, that's the trick.

05

Wrap-up

Let's gather finding the fastest way in a line.
When edges differ in distance,
fewer hops isn't the fast route.
So counting by nearness alone falls short.
Lock distances from the nearest point
and widen the boundary one point at a time,
and picking the best in front each moment,
you find the shortest distance to every point.

Click the key points in order to wrap up

Click the key points in order to wrap up. (Distance differs → hops won't do → lock nearest first → widen boundary)

When a map app finds you the fastest way,
this is what happens inside.
Locking distances from the near places
and widening the boundary little by little.
A simple rule, the best in front,
even on tangled roads of every distance,
brings you the fastest answer.

In one lineWhen edges have different distances, the route with fewer turns isn't the fastest. So just counting by nearness won't do. From the start, you lock in distances one point at a time, nearest first, and push the boundary of the locked region outward one point at a time. Each moment you pick the nearest point not yet locked, the best in front of you. Once the boundary spreads everywhere, you know the fastest distance to every point.
Algorithms
Was this helpful? Support seegongsik