In the previous video, we defined the two targets of part planning and how we are going to go about
it.
Focusing on first search for now.
We mentioned something of a recursive implementation.
Now what exactly is a recursive implementation?
It is an algorithmic implementation that involves recursion instead of the normal iterative case we
are used to daily.
Now the question we need to answer is what is recursion?
Let's start with the story.
Imagine you just arrived at Starbucks for your morning coffee.
The problem is, between you and your coffee, there is a long line of other morning coffee people.
You love everyone to bits, but it won't be too bad if they just disappear.
You don't like reading, especially when you don't know for how long.
So you go up to each customer, starting from the front, and start asking, what's their order?
You know, serve time for one cup and you know how to do the math.
So your curiosity has been questioned, right?
Yes and no.
Yes.
It does get you the answer you were looking for by going up to each person and asking who's order doing
the math and adding previous wait time to correct till the last person.
Did I mention going up to each customer and doing the math?
It's morning.
You don't want to do work before work.
So you have an idea where you would get your answer by doing very little book.
It is a recursive thought.
You will understand what that is in a minute.
You ask Mrs. Bink, how long will she have to wait to get served?
Now, this question being personal to Mrs. Bing as she is herself.
Concern of her wait time gets her curious.
She asks the next person of his weight.
This goes on until the first person that is out the counter.
He knows his order and there is no guide before him.
So he can just do the math.
That is, he wants one lady.
That would take around 3 minutes.
So Mr. Red answer backs to Mr. Green.
I would be waiting 3 minutes.
Mr. Green knows his order and his weight time.
He adds up.
Mr. Ridgway, time to get total wait.
Time till he gets up and tells to Mr. Orange.
This process decreases back to Mrs. Bink, who estimates her weight time, and now you finally know
how long you will have to wait before getting served.
There it is, 24 minutes.
That's enough time to do a quick match above cheap without worrying about missing coffee.
Few.
So that was the recursive thought.
You divide down the problem into smaller sub problems by asking the next person office we we're done.
Then this division went on until the fourth person which was the base condition as he knew exactly how
long he will have to wait.
So he answers back to the person before him.
Then we wrote back this answer to solve the previous dilemma sub problem and solve all the problems
eventually leads us to solving the original problem.
So this is recursion.
Easy, right?
Let's see it in the form of a nice looking flowchart.
So we start off by checking if we add the simplest case or the best condition.
If not, then we simply divide our problem into simpler and smaller sub problems.
This division goes on until we reach our simplest case.
If we are at the simplest case, this is the second step and we simply return the solution to the base
condition.
Once we have the solution to the base condition, we roll back the answer to solve the previously lived
problems.
This is the third and the final step and eventually leads us to solving the original problem.
That's it.
You have learned all of recursion.