title: Finding neighbor nodes in graph connection Algorithm
body: <p>I am working on a path finding problem. I have a 2D grid of evenly spaced nodes. I need an algorithm to find all 8 neighbors (if they exist) for each node so I can find all neighbor connections.</p>
  
  <p>The only way I know how to do it would be something like this:</p>
  
  <pre><code>for each node
   for every other node
       check position to find if it is neighboring if so add it to the nodes connection list
  </code></pre>
  
  <p>My concern is that this would be pretty inefficient <code>O(n^2)</code> and I imagine there is a better way of solving it.</p>
  
  <p>Any help would be great!</p>