Lets assume we have a rat maze as represented by the following NxM matrixwhere S is the start location and F is the end location.
S 0 0 0 0 0
1 1 0 0 0 0
1 0 1 0 0 0
1 0 1 0 0 0
0 1 0 1 0 0
1 0 0 0 1 0
0 1 1 1 1 F
The idea (as with any rat maze) is to traverse from S to F. The matrix can have only 0 and 1 as values. 1 represents a path that can be taken and 0 represents a blocked path.
We can make the following assumption:
S will always be (0,0) and F will always be (N,M).
As seen from above, there can be many paths from S to F.
How do we find the shortest (or longest) path from S to F without actually traversing all the possible paths.
Please provide an optimized algo.....
Just use BFS as all "edges" cost the same.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment