title: Breadth First Search using Adjacency Matrix
body: <p>I'm trying to implement a <code>BFS</code> algorithm that returns a <code>node[]</code> showing the order of traversal but using an <em>adjacency matrix</em>. However, the class I'm given for this task doesn't contain any instance variables in class so I have to implement it all with what is given here. It's traversing every element in the <code>10x10</code> grid of vertices instead of finding the shortest path.</p>
  <pre class="lang-java prettyprint-override"><code>    public Node[] breadthFirstSearch(Node start, Node target) {
          // TODO using the adjacency matrix
          LinkedList&lt;Node&gt; queue = new LinkedList&lt;&gt;();
          ArrayList&lt;Node&gt; visited = new ArrayList&lt;&gt;();
          queue.addLast(start);
          visited.add(start);
          
          while (!queue.isEmpty()) {
              Node curr = queue.removeFirst();
              if (curr.equals(target)) {
                  return (Node[]) visited.toArray();
              } else {
                  if (curr.getEdges().isEmpty()) {
                      return null;
                  } else {
                      queue.addAll((Collection&lt;? extends Node&gt;) start.getEdges().clone());
                  }
                  visited.add(curr);
              }
          }
          return null;
      }
  </code></pre>