Backtracking/Knight tour problem/c/knight_tour_problem.c
/* A recursive utility function to solve Knight Tour 
   problem */
A recursive utility function to solve Knight Tour
problem
A recursive utility function to solve Knight Tour problem
int solveKTUtil(int x, int y, int movei, int sol[N][N], 
                int xMove[N], int yMove[N]) 
{ 
   int k, next_x, next_y; 
   if (movei == N*N) 
       return true; 
   for (k = 0; k < 8; k++) 
   { 
       next_x = x + xMove[k]; 
       next_y = y + yMove[k]; 
       if (isSafe(next_x, next_y, sol)) 
       { 
         sol[next_x][next_y] = movei; 
         if (solveKTUtil(next_x, next_y, movei+1, sol, 
                         xMove, yMove) == true) 
             return true; 
         else
             sol[next_x][next_y] = -1;
       } 
   } 
   return false; 
}
int solveKTUtil ( int x , int y , int movei , int sol [ N ] [ N ] , int xMove [ N ] , int yMove [ N ] ) { int k , next_x , next_y ; if ( movei == N * N ) return true ; for ( k = 0 ; k < 8 ; k ++ ) { next_x = x + xMove [ k ] ; next_y = y + yMove [ k ] ; if ( isSafe ( next_x , next_y , sol ) ) { sol [ next_x ] [ next_y ] = movei ; if ( solveKTUtil ( next_x , next_y , movei + 1 , sol , xMove , yMove ) == true ) return true ; else sol [ next_x ] [ next_y ] = -1 ; } } return false ; }
A recursive utility function to solve Knight Tour
problem
A recursive utility function to solve Knight Tour problem
/* Try all next moves from the current coordinate x, y */ // backtracking 