title: Recursive algorithm with Depth First Search
body: <p>Suppose I have the following maze: (not formatted properly) </p>
  
  <pre><code>#########################################
  S... #... # # #... #
  ###.# ##### #.#.### # ### # ###.#.# #####
  #...# #...# #.#...# # # #.#.# #...#
  #.#####.#.###.###.##### ##### #.#.###.#.#
  #.....#.#..... #...# #.#.....#.#
  # ###.#.####### ###.###########.#######.#
  # #.#.# # #...#......... # #.#
  ### #.#.# ### #######.#.########### # #.#
  # # #.#.# # # # #...# # # .#
  # # #.#.# # ### # # ##### ### # #######.#
  # #...# # # # #                        .E
  #########################################
  </code></pre>
  
  <p>S represents start of the maze and E represents end of the maze. I have two given classes; <code>Maze</code> and <code>Cell</code> . I have to build the following recursive helper method to find the solution of the maze:</p>
  
  <pre><code>  -findPath(currentMaze:Maze, current:Cell, path:ArrayList&lt;Cell&gt;):ArrayList&lt;Cell
  </code></pre>
  
  <blockquote>
    <p>This method
    recursively finds a path from the start of the currentMaze to its end that goes through the
    current Cell. The path is an ArrayList of the sequence of cells that was followed to get from
    the start of the maze to the current cell (i.e., the path explored so far). In order to avoid paths
    that are longer than needed, the algorithm should avoid revisiting cells already in this path. The
    algorithm should return null if there is no path from current to the end that only goes through
    each Cell at most once. Otherwise, it should return the complete path from the start of the maze
    to the end as a sequence of Cells in an ArrayList.
    You must implement this as a recursive algorithm. In order to explore all paths through neighbors that have not yet been
    visited, you will want to make use of Maze’s getNeighbors. </p>
  </blockquote>
  
  <p>To build this recursive method, I'm given the following methods:</p>
  
  <pre><code>+getStartCell():Cell Returns the start Cell of the maze
  +getEndCell():Cell Returns the end Cell of the maze
  
  
   +getNeighbors(currentCell:Cell):
  ArrayList&lt;Cell&gt;
  Returns a list of all the cells that are connected to
  currentCell. If there is a wall between
  currentCell and its neighbor, it is not added to this
  collection. 
  </code></pre>
  
  <p>So far this is what I did: </p>
  
  <pre><code> private static ArrayList &lt;Cell&gt; findPath(Maze currentMaze,Cell current,ArrayList &lt;Cell&gt; path){
     // Base Case
     if (current == currentMaze.getEndCell()) {
      return path;
     }
   if(currentMaze.getNeighbors(current).size()!=0)
  currentMaze.getStartCell();
  currentMaze.getNeighbors(current);
  currentMaze.getEndCell();
  }
  }
  </code></pre>
  
  <p>I'm really struggling to build this method.</p>