Solving Classic Maze Problem

Classic Maze!!!!!

Classic Maze! is a standard problem. What we have to do is 'Find a Path'. How?? we'll see.
Generally, in Maze input is given in the form of 0 and 1, 0 denoting the accessible path whereas 1 denotes "Hurdles" in our path.

The Question is-
Which approach should we take?
any guesses, huh!!
Well!!
We should Follow Recursive approach. Confused Why?

Okay, So now Question is what lead to Recursion??

Think about it in this way >>> We need to find a Path that means we need to connect zeros from start to end. Simple!, So all we need to do is check our array and trace a path. Yes! we need to trace a path. Whenever word "Tracing" comes it is more likely to be related to recursion.

Let's Talk about Recursion.
Recursion has recursive equation and base cases.

Think Of , What Our Base Cases Will be??
>> Our End!!, right.
but here we have other cases too... What they Can be??

The Points, at which we need to stop searching further... they can be boundaries or 1.

So, We Will Stop Our Searching Further  Whenever It Is our End or 1 or We Are Out Of Boundaries.

Now, what we need is Recursive Equations.

Recursion is all about dividing a case into smaller cases.

Here, we need to find a "Path". So for recursion we need to find a "Path" in terms of finding path.

How we can Do these??

What will you do if you need to find a path. Sure, You will check possibility of moving NORTH, SOUTH, EAST & WEST. right!
That's what we need to do here.

So, now we have a way to find our path and cases to stop searching further, that's all we need for recursion.

But we do need some more things to help us.
Think!
What about the points we already checked.
 We will mark them as '+' or 'x'.
+ will denote the points forming way to end.
x will denote the point from where no possible way exist.

So, all you need to do is some up all the information. and create a program.


Below Is What Your Function Should Look Like-

Fn findPath:
                   check End;
                   check Boundary;
                   check One;
                   check Zero : mark +;
                   Move North;
                   Move East;
                   Move South;
                   Move West;
        Mark x;
end findpath;

Comments

Popular Posts