diff --git a/Backtracking/Graph Coloring.cpp b/Backtracking/Graph Coloring.cpp deleted file mode 100644 index 34a4299..0000000 --- a/Backtracking/Graph Coloring.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include - -// Number of vertices in the graph -#define V 4 - -void printSolution(int color[]); - -/* A utility function to check if the current color assignment - is safe for vertex v */ -bool isSafe (int v, bool graph[V][V], int color[], int c) -{ - for (int i = 0; i < V; i++) - if (graph[v][i] && c == color[i]) - return false; - return true; -} - -/* A recursive utility function to solve m coloring problem */ -void graphColoring(bool graph[V][V], int m, int color[], int v) -{ - /* base case: If all vertices are assigned a color then - return true */ - if (v == V){ - printSolution(color); - return; - } - - /* Consider this vertex v and try different colors */ - for (int c = 1; c <= m; c++) - { - /* Check if assignment of color c to v is fine*/ - if (isSafe(v, graph, color, c)) - { - color[v] = c; - - /* recur to assign colors to rest of the vertices */ - graphColoring (graph, m, color, v+1); - - - /* If assigning color c doesn't lead to a solution - then remove it */ - color[v] = 0; - } - } - -} - -/* A utility function to print solution */ -void printSolution(int color[]) -{ - printf(" Following are the assigned colors \n"); - for (int i = 0; i < V; i++) - printf(" %d ", color[i]); - printf("\n"); -} - -// driver program to test above function -int main() -{ - /* Create following graph and test whether it is 3 colorable - (3)---(2) - | / | - | / | - | / | - (0)---(1) - */ - bool graph[V][V] = {{0, 1, 1, 1}, - {1, 0, 1, 0}, - {1, 1, 0, 1}, - {1, 0, 1, 0}, - }; - int m = 3; // Number of colors - - int color[V]; - - for (int i = 0; i < V; i++) - color[i] = 0; - - graphColoring(graph, m, color, 0); - return 0; -} diff --git a/Backtracking/N Queens.cpp b/Backtracking/N Queens.cpp deleted file mode 100644 index cf14d65..0000000 --- a/Backtracking/N Queens.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include -#define N 4 -using namespace std; - -void printSolution(int board[N][N]) -{ - cout<<"\n"; - for (int i = 0; i < N; i++) - { - for (int j = 0; j < N; j++) - cout<<""<=0 && j>=0; i--, j--) - if (board[i][j]) - return false; - - /* Check lower diagonal on left side */ - for (i=row, j=col; j>=0 && i= N){ - printSolution(board); - return; - } - - /* Consider this column and try placing - this queen in all rows one by one */ - for (int i = 0; i < N; i++) - { - /* Check if queen can be placed on - board[i][col] */ - if ( isSafe(board, i, col) ) - { - /* Place this queen in board[i][col] */ -// cout<<"\n"< -#define size 4 - -using namespace std; - -int solveMaze(int currposrow,int currposcol,int maze[size][size],int soln[size][size]) -{ - if((currposrow==size-1) && (currposcol==size-1)) - { - soln[currposrow][currposcol]=1; - for(int i=0;i -using namespace std; -///N=9; -int n=9; - - -bool isPossible(int mat[][9],int i,int j,int no){ - ///Row or col nahin hona chahiye - for(int x=0;x