Posts

Showing posts from April, 2014

Solve the Maze by DFS (Depth First Search)

Image
In maze traversal, we must have to traverse deeper as soon as possible through the selected particular path until we reach the dead end. When we are on the way in that path, if it closed then we must have to back track to previous state to select another path. For this reasons, this traversal very similar to the DFS algorithm. Strategy for exploring Maze:  To convert given maze to a graph mark each intersection, corner and dead end (vertex) visited.  We mark each corridor (edge) as traversed.  We keep track of the path back to the entrance (start vertex) by means of a rope. (recursion stack) According to above all reasons, DFS (Depth First Search) algorithm very similar to a classic strategy for exploring a maze. Implementation in C# Graph.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Maze_traversal {     class Graph     {         private int maxVertex;         private Vertex[] vList;         private int[