Vertice removal at end in SearchMaze

#1

I am trying to understand the SearchMaze problem and I don’t understand the need of removing the last entry from the path if no path to exist vertex was found which is done here

Why is this needed?

Thanks.

0 Likes

#2

Since we add an entry always in path.add(next), if we cannot find an path (which will return true), we need to clean that by removing that entry. It is common programming skill used in implementing DFS-like search while having one variable to store the result (i.e., path).

Feel free to let us know if you have any problem.

0 Likes