title: Traverse a graph represented in an adjacency matrix
body: <p>I am wanting to use the depth-first and breadth-first methods for traversing a graph. I have done this on a simple list of nodes before, but I have never tried it with an adjacency matrix and I honestly don't even know where to start. </p>
  
  <p>Here is my matrix:</p>
  
  <pre><code>999999999 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 
  1 999999999 0 3 1 0 0 0 0 0 0 0 0 0 0 0 
  1 0 999999999 3 0 1 0 0 0 0 0 0 0 0 0 0 
  0 3 3 999999999 0 0 0 8 0 0 0 0 0 0 0 0 
  0 1 0 0 999999999 0 1 3 0 0 0 0 0 0 0 0 
  0 0 1 0 0 999999999 0 3 1 0 0 0 0 0 0 0 
  0 0 0 0 1 0 999999999 0 0 3 0 1 0 0 0 0 
  0 0 0 8 3 3 0 999999999 0 8 8 0 3 0 0 0 
  0 0 0 0 0 1 0 0 999999999 0 3 0 0 1 0 0 
  0 0 0 0 0 0 3 8 0 999999999 0 0 0 0 3 0 
  0 0 0 0 0 0 0 8 3 0 999999999 0 0 0 0 3 
  0 0 0 0 0 0 1 0 0 0 0 999999999 0 0 1 0 
  0 0 0 0 0 0 0 3 0 0 0 0 999999999 0 1 1 
  0 0 0 0 0 0 0 0 1 0 0 0 0 999999999 0 1 
  0 0 0 0 0 0 0 0 0 3 0 1 1 0 999999999 0 
  0 0 0 0 0 0 0 0 0 0 3 0 1 1 0 999999999
  </code></pre>
  
  <p>Here is how I created this matrix (C#):</p>
  
  <pre><code>private static int[,] CreateMatrix()
          {
              int A = 0;
              int B = 1;
              int C = 2;
              int D = 3;
              int E = 4;
              int F = 5;
              int G = 6;
              int H = 7;
              int I = 8;
              int J = 9;
              int K = 10;
              int L = 11;
              int M = 12;
              int N = 13;
              int O = 14;
              int P = 15;
  
              int[,] matrix = new int[16, 16];
  
              matrix[A, B] = 1;
              matrix[A, C] = 1;
              matrix[B, D] = 3;
              matrix[B, E] = 1;
              matrix[C, D] = 3;
              matrix[C, F] = 1;
              matrix[D, H] = 8;
              matrix[E, G] = 1;
              matrix[E, H] = 3;
              matrix[F, H] = 3;
              matrix[F, I] = 1;
              matrix[G, J] = 3;
              matrix[G, L] = 1;
              matrix[H, J] = 8;
              matrix[H, K] = 8;
              matrix[H, M] = 3;
              matrix[I, K] = 3;
              matrix[I, N] = 1;
              matrix[J, O] = 3;
              matrix[K, P] = 3;
              matrix[L, O] = 1;
              matrix[M, O] = 1;
              matrix[M, P] = 1;
              matrix[N, P] = 1;
  
  
              matrix[B, A] = 1;
              matrix[C, A] = 1;
              matrix[D, B] = 3;
              matrix[E, B] = 1;
              matrix[D, C] = 3;
              matrix[F, C] = 1;
              matrix[H, D] = 8;
              matrix[G, E] = 1;
              matrix[H, E] = 3;
              matrix[H, F] = 3;
              matrix[I, F] = 1;
              matrix[J, G] = 3;
              matrix[L, G] = 1;
              matrix[J, H] = 8;
              matrix[K, H] = 8;
              matrix[M, H] = 3;
              matrix[K, I] = 3;
              matrix[N, I] = 1;
              matrix[O, J] = 3;
              matrix[P, K] = 3;
              matrix[O, L] = 1;
              matrix[O, M] = 1;
              matrix[P, M] = 1;
              matrix[P, N] = 1;
  
              for (int i = 0; i &lt; 16; i++)
              {
                  for (int j = 0; j &lt; 16; j++)
                  {
                      if (matrix[i, j] == 0)
                          matrix[i, j] = 0;
  
                      if (i == j)
                          matrix[i, j] = 999999999;
  
                  }
              }
  
              return matrix;
          }
  </code></pre>
  
  <p>Any help would be appreciated!!</p>
  
  <p>Graph that this matrix represents:</p>
  
  <p><img src="https://i.stack.imgur.com/TPXvN.png" alt="enter image description here"></p>