Good enough instead of perfect
You saw it last time: for some problems the cases explode, so chasing the perfect answer to the end would take a lifetime. So do we give up? Not quite. Even if you can't get the perfect answer, a "good enough" one is often quick to find. You give up a little, and save a lot of time.
Set perfect aside for now
Here's a hard problem.
To find the perfect answer
you'd have to weigh every case,
and there are an enormous number.
Go all the way
and you'll surely get the very best.
But when
would that ever finish?
Press to count it out.
Chase the perfect answer to the end. (Cases pile up and time explodes → no end in sight)
The number grows too fast.
Add just a few more
and there's many times as much to check.
So waiting for the perfect answer
all the way to the end
isn't realistic sometimes.
Still, we can't
just throw up our hands.
A good enough answer, fast
Here's an idea.
What if it doesn't have to be
the very best?
Instead of aiming for perfect,
just quickly
pull out a
"pretty good" answer.
Like we did with greedy,
picking the good thing
in front of us, briskly.
A quick rough answer vs the perfect one. (The rough one comes instantly, the gap is small)
Look.
The rough answer popped out in a blink,
yet it's not far
from the perfect one.
A touch short,
but perfectly usable.
For many cases
this much is plenty.
It guarantees how good it is
But there's one worry.
Can we trust that
"pretty good" answer?
What if it's
secretly terrible?
So the clever methods
come with a promise.
They say, "this answer
won't be much worse
than the very best."
Guaranteed within 1.5x of the best. (Whatever answer comes, it stays inside this line, the worst is capped)
This is the truly neat part.
Draw a line like
"within 1.5x of the best,"
and however bad the answer,
it can't cross that line.
Not perfect,
but we know exactly
how far off it could be.
That's completely different
from a vague guess.
Trade accuracy for time
In the end it's a balance.
Spend more time
and the answer gets more accurate;
save time
and it gets a bit rougher.
Neither side is
simply the right one.
In a hurry, take the fast side;
need precision, the accurate side.
Move the slider
and pick a spot between them.
More time, more accurate; less time, less accurate. (Where to stop is ours to choose)
This balance
is the heart of all algorithms.
The fast road and the accurate road,
the simple road and the careful road.
Each time, we've been
choosing what to give up
and what to gain.
Knowing a good method
means reading this balance well.
The road that brought us here
We've walked a long road.
Starting from solving in order,
lining up, searching,
measuring cost,
splitting, linking, choosing.
We saw that some problems are truly hard,
and that even so,
a good enough answer exists.
Press to look back
over that road at once.
Four things this area gave us. (Good methods, speed, strategy, knowing the limits and trading wisely)
We can't solve
every problem perfectly.
But that doesn't mean
we're powerless.
With fast methods,
with smart strategies,
knowing the limits and trading wisely,
even in front of a hard problem
you can hold
a usable answer in your hand.
That's the power
algorithms give us.