CS 111 Introduction to Data Structures Outside Programming Assignment I Due: Sep
ID: 3562731 • Letter: C
Question
CS 111 Introduction to Data Structures Outside Programming Assignment I Due: Sept. 23, 2014 AT THE START OF CLASS The four-color theorem states that any map in a plane can be colored using four-colors in such a way that regions sharing a common boundary (other than a single point) do not share the same color. This problem is sometimes also called Guthrie's problem after F. Guthrie, who first conjectured the theorem in 1852. The problem at hand is to take a map separated into regions as expressed in an adjacency matrix and using four colors, color the map such that no two contiguous regions share the same color. We will use an adjacency matrix to encode which region borders on which other region. The columns and rows of the matrix are the regions while the cells contain a 0 if the two regions are not adjacent and a 1 if they border. Create a recursive backtracking solution which accepts as interactive input from the user the number of regions in the map and the filename of the adjacency matrix expressing the maps makeup. Your output should be similar to Or whatever four colors you choose (and if you want you could have the user choose the four colors but that it not mandatory). Consider the following map with four regions Its adjacency matrix would beExplanation / Answer
import matrix;
class Matrix
{
public static void main(String args[])
{
int i,j,k;
int mat1 [][]={ {1,2,3}, {4,5,6}, {7,8,9} };
int mat2 [][]={ {10,11,12}, {13,14,15}, {16,17,18} };
//Matrix A
System.out.println(" Matrix A:");
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
System.out.print(" "+mat1[i][j]);
System.out.println("");
}
//Matrix B
System.out.println(" Matrix B:");
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
System.out.print(" "+mat2[i][j]);
System.out.println("");
}
System.out.println(" Operation ON Matrices 1.Addition ");
int sum [][] = new int [3][3];
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
sum[i][j] = mat1[i][j] + mat2[i][j];
System.out.print(" " + sum[i][j]);
}
System.out.println("");
}
System.out.println("2.Subtraction ");
int diff[][] = new int[3][3];
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
diff [i][j] = mat1[i][j] - mat2[i][j];
System.out.print(" "+ diff[i][j]);
}
System.out.println("");
}
System.out.println("3. Transpose Of A ");
int trans[][] = new int[3][3];
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
trans [i][j] = mat1[j][i];
System.out.print(" "+ trans[i][j]);
}
System.out.println("");
}
System.out.println("4.Multiplication ");
int prod[][] = new int[3][3];
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
prod[i][j] = 0;
{
for(k=0;k< 3;k++)
prod[i][j] = prod[i][j]+mat1[i][k]*mat2[k][j];
}
System.out.print(" "+ prod[i][j]);
}
System.out.println("");
}
}
}
/************* OUTPUT ***************
Matrix A:
1 2 3
4 5 6
7 8 9
Matrix B:
10 11 12
13 14 15
16 17 18
Operation ON Matrices
1.Addition
11 13 15
17 19 21
23 25 27
2.Subtraction
-9 -9 -9
-9 -9 -9
-9 -9 -9
3. Transpose Of A
1 4 7
2 5 8
3 6 9
4.Multiplication
84 90 96
201 216 231
318 342 366
*/