title: Greedy Recursive Search
body: <p>My professor gave us an assignment where I need to search around a given point in a grid for all other spots that makes up a group (in this example I need to find the number of spots that in a "L" shape within the problem).</p>
  
  <p>So the grid is 10x10, and my professor has given us a spot to start with. My professor gave us an idea which is to check the neighboring spots, and add it to a set, if the spot is newly found (which will be in the set) then recursively call that method.</p>
  
  <pre><code>private Spot findSpots(Set&lt;Spot&gt; spots, Set&lt;Spot&gt; activeSpots, Spot initial) {
      Spot newSpot = null;
  
  
      Set&lt;Spot&gt; activeSet = new HashSet&lt;Spot&gt;();
      checkAround(activeSet, new Spot(initial.i - 1, initial.j));
      checkAround(activeSet, new Spot(initial.i + 1, initial.j));
      checkAround(activeSet, new Spot(initial.i, initial.j - 1));
      checkAround(activeSet, new Spot(initial.i, initial.j + 1));
  
  
      for (Spot spot : activeSet) {
          newSpot = findSpots(spots, activeSpots, spot);
          if (grid[newSpot.i][newSpot.j] == true)
              spots.add(newSpot);
      }
  
      return newSpot;
   }
   private boolean checkAround(Set&lt;Spot&gt; spots, Spot spot) {
      if (!spots.contains(spot)) {
          spots.add(spot);
          return true;
      }
      return false;
   }
  </code></pre>
  
  <p>I know I need a boundary condition (or else I will get stackoverflow exceptions), but I need help in the logic.</p>