title: Implementing a tree for a maze to use in DFS, BFS
body: <p>My program is taking a char array as input from a file. The array looks like this:</p>
  
  <pre><code>"#########",
  "# #     #",
  "# ##  # #",
  "#     # #",
  "### # ###",
  "#   # # #",
  "# # #####",
  "#   #   #",
  "#########",
  </code></pre>
  
  <p>I am implementing DFS and BFS to solve this maze with starting from [1,1] and ending in [width - 1,height - 1].</p>
  
  <p>I thought of making a tree representing the maze and then traversing the tree using each algorithm respectively.</p>
  
  <p>I will start at each row and scan for empty cells, at each empty cell every cell that is to its right, left and bottom are going to be children of that cell. It looks something like this:</p>
  
  <pre><code>    for (int i = 0; i &lt; width; i++)
      {
          for (int j = 0; j &lt; height; j++)
          {
              if (isEmpty(maze[i][j]))
                      {
                           putChildren(maze[i-1][j], maze[i][j+1], maze[i+1][j]);
                           //this will check if it's a wall first
                      }       
      }
  </code></pre>
  
  <p>Is it a viable tactic to implement the tree like this and then use it to traverse the tree with DFS and BFS or I should I go at this another way?</p>