title: What data structure to use for this algorithm?
body: <p>I have a <code>Matrix [N][M]</code>. I have filled this matrix with obstacles represented by <code>-1</code> and space for moving represented by <code>0</code>. I have also a person A represented by <code>-2</code>. This person have to check up, down, right and left to check if there is an obstacle. If there is not, then increment by <code>1</code>, place it in the current cell. When you finish with the checks go to the neighbors of that cell and do the same checks for its neighbors.</p>
  
  <p>Obviously,the algorithm starts where person A is located and checks the above stuff that I wrote. My job is to find a particular cell where person A and person B could meet but the path must be the shortest possible. I guess that the algorithm should remember which cells have incremented. </p>
  
  <ul>
  <li>Should I use some kind of data structure for this task ? </li>
  <li>And, when does the algorithm has to stop ?</li>
  </ul>