title: Algorithm of N queens
body: <pre><code>Algorithm NQueens ( k, n) //Prints all Solution to the n-queens problem
  {
      for i := 1 to n do
      {
          if Place (k, i) then
          {
              x[k] := i;
              if ( k = n) then write ( x [1 : n]
              else NQueens ( k+1, n);
          }
      }
  }
  
  Algorithm Place (k, i)
  {
      for j := 1 to k-1 do
          if (( x[ j ] = // in the same column
             or (Abs( x [ j ] - i) =Abs ( j – k ))) // or in the same diagonal
          then return false;
          return true;
  }
  </code></pre>
  
  <p>The above code is for solving N Queens problem using backtracking.I think that it can place the first 2 queens of two rows in respective columns and then when it comes to 3rd row queen it can't be placed as no queen needs to be attacking and it will simply exit from Algorithm N queens...So how is this algorithm implements backtracking?</p>