Given a NxN matrix (which contains Boolean values - true / false).
We will define:
true region in an array as a maximum collection of adjacent cells that all have a true value.
Cells located diagonally to each other are not considered adjacent.
In this example, there are 3 true areas:
True Regions
My Solution attemp in Java:
public static int (boolean[][] mat) {
return GetTrueRegions(mat, 0, 0);
}
public static int GetTrueRegions(boolean[][] m, int i , int j) {
final boolean VISITED = false;
if (i == m.length - 1 && j == m[0].length - 1)
return 0;
// avoid repeat a cell
boolean temp = m[i][j];
m[i][j] = VISITED;
// recursion for all neighbors
int up = -1, down = -1, left = -1, right = -1;
if (i - 1 >= 0 && m[i-1][j] )
up = GetTrueRegions(m, i - 1, j);
if (i + 1 < m.length && m[i+1][j])
down = GetTrueRegions(m, i + 1, j);
if (j - 1 >= 0 && m[i][j-1])
left = GetTrueRegions(m, i, j - 1);
if (j + 1 < m[0].length && m[i][j+1] )
right = GetTrueRegions(m, i, j + 1);
// couldn't find a path
if (temp) {
return 1 + GetTrueRegions(m, i, j + 1);
}
if (up == -1 && down == -1 && left == -1 && right == -1 )
return GetTrueRegions(m, i, j +1);
return up + down + left + right;
}
this obviously not working.
I was thinking about going through each cell, and if the cell has true value, adding 1 to the total regions(somehow), and put the value false to him and to each adjacent cell(mark the region as "visited").
though I find it hard for me to get the base cases, and how to get every region value.
try to look at something like that:
public static int GetTrueRegions(boolean[][] mat)
{
return GetTrueRegions(mat, 0, 0);
}
private static int GetTrueRegions(boolean[][] m, int i, int j)
{
if (j == m[0].length)
return 0;
if (i == m.length)
return GetTrueRegions(m, 0, j + 1);
// found a region
if (m[i][j])
{
// mark the entire region, to avoid duplications
markRegionAsFalse(m, i, j);
// count 1 region and proceed
return 1 + GetTrueRegions(m, i + 1, j);
}
// proceed...
return GetTrueRegions(m, i + 1, j);
}
private static void markRegionAsFalse(boolean[][] matrix, int row, int col)
{
// just visited...
matrix[row][col] = false;
if(row - 1 >= 0 && matrix[row - 1][col]) // move up and mark cell if true
markRegionAsFalse(matrix, row - 1, col);
if (row < matrix.length - 1 && matrix[row + 1][col]) // move down and mark cell if true
markRegionAsFalse(matrix, row + 1, col);
if (col < matrix.length - 1 && matrix[row][col + 1]) // move right and mark cell if true
markRegionAsFalse(matrix, row, col + 1);
if(col - 1 >= 0 && matrix[row][col - 1]) // move left and mark cell if true
markRegionAsFalse(matrix, row, col - 1);
}
Related
I am fairly new to Java and I have been working on a Minesweeper game. I am trying to get the adjacent cells to be revealed recursively when an empty cell is clicked. I do this by calling showCell() shown below:
Cells array declaration and population:
private final Cell[][] cells;
public void newGame()
{
numMinesLeft = NUM_MINES;
numCellsLeft = NUM_ROWS * NUM_COLS;
hasHitMine = false;
Cell[] newCells = new Cell[NUM_ROWS * NUM_COLS];
int k = 0; // index in newCells
// create the cells with the mines
while (k < NUM_MINES && k < newCells.length)
{
newCells[k] = new Cell(MINE);
k++;
}
// create the cells without the mines
while (k < newCells.length)
{
newCells[k] = new Cell();
k++;
}
// uniformly mix newCells
for (k = newCells.length; k > 1;)
{
int r = generator.nextInt(k);
k--;
// interchange newCells[r] and newCells[k]
Cell temp = newCells[k];
newCells[k] = newCells[r];
newCells[r] = temp;
}
k = 0;
// place cells into the cells array
for (int i = 0; i < NUM_ROWS; ++i)
{
for (int j = 0; j < NUM_COLS; ++j)
{
cells[i][j] = newCells[k];
k++;
}
}
for(int i = 0; i<NUM_ROWS; i++)
{
for (int j = 0; j<NUM_COLS; j++)
{
int numOfBorderMines = 0;
if (cells[i][j].value != MINE)
{
if(isInTheGrid(i-1, j) == true)
{
if (cells[i-1][j].value == MINE )
{
numOfBorderMines++;
}
}
if(isInTheGrid(i+1, j) == true)
{
if (cells[i+1][j].value == MINE )
{
numOfBorderMines++;
}
}
if(isInTheGrid(i, j - 1) == true)
{
if (cells[i][j - 1].value == MINE )
{
numOfBorderMines++;
}
}
if(isInTheGrid(i, j + 1) == true)
{
if (cells[i][j + 1].value == MINE )
{
numOfBorderMines++;
}
}
if(isInTheGrid(i - 1, j + 1) == true)
{
if (cells[i - 1][j + 1].value == MINE )
{
numOfBorderMines++;
}
}
if(isInTheGrid(i + 1, j - 1) == true)
{
if (cells[i + 1][j - 1].value == MINE )
{
numOfBorderMines++;
}
}
if(isInTheGrid(i + 1, j + 1) == true)
{
if (cells[i + 1][j + 1].value == MINE )
{
numOfBorderMines++;
}
}
if(isInTheGrid(i - 1, j - 1) == true)
{
if (cells[i - 1][j - 1].value == MINE )
{
numOfBorderMines++;
}
}
cells[i][j].value = numOfBorderMines;
}
}
}
}
toggleFlag()
public void toggleFlag(int row, int col)
{
if (isCellShowing(row, col) || isOver()) return;
if (isCellFlagged(row, col))
{
// unflag cell
cells[row][col].hasFlag = false;
numMinesLeft++;
numCellsLeft++;
}
else if (numMinesLeft > 0)
{
// flag cell
cells[row][col].hasFlag = true;
numMinesLeft--;
numCellsLeft--;
}
ui.updateCell(row, col);
}
showCell()
public void showCell(int row, int col)
{
// checks is cell has been flagged or if the game is over, otherwise it reveals the cell
if(isCellFlagged(row, col) == true || isOver())
{
return;
}
else
{
cells[row][col].isShowing = true;
ui.updateCell(row, col);
}
// checks if cell has a mine and triggers hasHitMine otherwise subtracts 1 from class variable numCellsLeft
if (cells[row][col].value == MINE)
{
hasHitMine = true;
}
else
{
numCellsLeft--;
}
// if there are no mines adjacent, recursively reveal the adjacent cells
if(cells[row][col].value == 0)
{
showCell(row + 1, col);
showCell(row - 1, col);
showCell(row, col + 1);
showCell(row, col -1);
showCell(row + 1, col - 1);
showCell(row + 1, col + 1);
showCell(row - 1, col - 1);
showCell(row - 1, col + 1);
}
}
The problem I am having is when I hit this portion of the code and click an empty cell, it reveals all cells adjacent continuously down a column or a row in one direction. I can't get my implementation of recursion right, perhaps I am approaching it wrong. My idea was to reveal each adjacent cell according to the grid position.
I solved my problem by implementing Tail Recursion. Here is my updated showCell() method and tail recursion method:
public void showCell(int row, int col)
{
// checks is cell has been flagged or if the game is over, otherwise it reveals the cell
if(isCellFlagged(row, col) == true || isOver())
{
return;
}
else
{
cells[row][col].isShowing = true;
ui.updateCell(row, col);
}
// checks if cell has a mine and triggers hasHitMine otherwise subtracts 1 from class variable numCellsLeft
if (cells[row][col].value == MINE)
{
hasHitMine = true;
}
else
{
numCellsLeft--;
}
// if there are no mines adjacent, recursively reveal the adjacent cells
if(cells[row][col].value == 0)
{
if(isInTheGrid(row - 1, col) == true)
{
showCell(row - 1, col, cells[row - 1][col].isShowing);
}
if(isInTheGrid(row + 1, col) == true)
{
showCell(row + 1, col, cells[row + 1][col].isShowing);
}
if(isInTheGrid(row, col - 1) == true)
{
showCell(row, col - 1, cells[row][col - 1].isShowing);
}
if(isInTheGrid(row, col + 1) == true)
{
showCell(row, col + 1, cells[row][col + 1].isShowing);
}
if(isInTheGrid(row + 1, col - 1) == true)
{
showCell(row + 1, col - 1, cells[row + 1][col - 1].isShowing);
}
if(isInTheGrid(row - 1, col + 1) == true)
{
showCell(row - 1, col + 1, cells[row - 1][col + 1].isShowing);
}
if(isInTheGrid(row + 1, col + 1) == true)
{
showCell(row + 1, col + 1, cells[row + 1][col + 1].isShowing);
}
if(isInTheGrid(row - 1, col - 1) == true)
{
showCell(row - 1, col - 1, cells[row - 1][col - 1].isShowing);
}
}
else
{
return;
}
}
public boolean isInTheGrid(int x, int y)
{
if (x < 0 || y < 0) return false;
if(x >= NUM_ROWS || y >= NUM_COLS) return false;
return true;
}
public void showCell(int row, int col, boolean isShown)
{
if (isShown != true)
{
cells[row][col].isShowing = true;
ui.updateCell(row, col);
}
else
{
return;
}
}
When you call show cell for surrounding cells, you want to make sure that you don't re-show the cell you called it from, or past cells that were shown from the previous calls in the recursion stack.
If I understood your question correctly, I believe you are referring the case in Minesweeper where if you click on an empty cell, then it will reveal the adjacent empty cells.
Can someone explain to me the time complexity for these three methods and help me understand why it is that time complexity. Both methods takes in a matrix and finds all its surrounding neighbours. The first method is done through recursion and the second one is done through iterations and stacks and third method is done through tail recursion.
Here is the first method:
public static int ExploreAndLabelColony(char[][] grid, int i, int j, char c) {
grid[i][j] = c;
int count = 1;
if ((i>0 && i<grid.length && j<grid[0].length) && (grid[i-1][j] == '1')) { //vertical top
count += ExploreAndLabelColony(grid, i-1,j,c);
}
if (i+1<grid.length && j<grid[0].length && grid[i+1][j] == '1') { //vertical bottom
count +=ExploreAndLabelColony(grid, i+1,j,c);
}
if (j>0 && i<grid.length && j<grid[0].length && grid[i][j-1] == '1') { //horizontal left
count +=ExploreAndLabelColony(grid, i,j-1,c);
}
if (i<grid.length && j+1<grid[0].length && grid[i][j+1] == '1') { //horizontal right
count +=ExploreAndLabelColony(grid, i,j+1,c);
}
if (i+1<grid.length && j+1<grid[0].length && grid[i+1][j+1] == '1') { //diagonal bottom right
count +=ExploreAndLabelColony(grid, i+1,j+1,c);
}
if (j>0 && i+1<grid.length && j<grid[0].length && grid[i+1][j-1] == '1') { //diagonal bottom left
count +=ExploreAndLabelColony(grid, i+1,j-1,c);
}
if (i>0 && i<grid.length && j+1<grid[0].length && grid[i-1][j+1] == '1') { //diagonal top right
count += ExploreAndLabelColony(grid, i-1,j+1,c);
}
if (i>0 && j>0 && i<grid.length && j<grid[0].length && grid[i-1][j-1] == '1') { //diagonal top left
count +=ExploreAndLabelColony(grid, i-1,j-1,c);
}
return count;
}
}
This is the second method:
public static int ExploreAndLabelColony(char[][] grid, int i, int j, char c) {
Stack<String> strStack = new Stack<>();
strStack.push(i + "," + j);
while (!strStack.empty()) {
String x = strStack.pop();
int row = Integer.parseInt(x.split(",")[0]);
int col = Integer.parseInt(x.split(",")[1]);
if(row<0 || col<0 || row>=grid.length || col>=grid[0].length || visited[row][col] || grid[row][col]!='1')
continue;
visited[row][col]=true;
grid[row][col]=c;
count++;
strStack.push(row + "," + (col-1)); //left
strStack.push(row + "," + (col+1)); //right
strStack.push((row-1) + "," + col); //up
strStack.push((row+1) + "," + col); //down
strStack.push((row-1) + "," + (col-1)); //left & up
strStack.push((row-1) + "," + (col+1)); //right & up
strStack.push((row+1) + "," + (col-1)); //left & down
strStack.push((row+1) + "," + (col+1)); //right & down
}
return count;
}
This is the third method:
static int ExploreAndLabelColony(Point point, char[][] grid, char c, int count) {
if (point == null) {
return count; // no more work
}
int i = point.i;
int j = point.j;
point = point.next;
if (i < 0 || j < 0 || i >= grid.length || j >= grid[0].length) {
} else if (grid[i][j] != '1') {
} else {
grid[i][j] = c; // label
count++;
point = new Point(i - 1, j - 1, point);
point = new Point(i - 1, j, point);
point = new Point(i - 1, j + 1, point);
point = new Point(i, j - 1, point);
point = new Point(i, j + 1, point);
point = new Point(i + 1, j - 1, point);
point = new Point(i + 1, j, point);
point = new Point(i + 1, j + 1, point);
}
return ExploreAndLabelColony(point, grid, c, count);
}
Given n rows and m cols the time complexity should be O(mn) for both. Since you are passing grid by reference and not revisiting visited cells this is a depth first search. The second method is the same as the first method but replaces the call stack in the first method with your own stack.
I am trying to find all adjacent elements in the matrix. Adjacent refers to elements being right beside each other either horizontal, vertical and diagonal elements. However it is giving me java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5. I am not sure why, any help would be much appreciated! Also the program needs to be recursive !
class matrixAdjacent
{
public static void main(String[] args)
{
char grid[][] = {{'0','0','0','1','1','0','1','1','0','0','0','1','1','1','0','1','1','1','0','1'},
{'1','0','0','0','0','1','0','0','0','1','0','0','0','0','0','1','1','1','1','1'},
{'0','1','0','0','1','0','0','0','1','0','1','0','0','0','0','0','0','1','1','1'},
{'1','1','1','0','0','1','0','1','0','0','0','0','1','0','1','1','0','1','1','0'},
{'0','1','1','1','0','1','1','1','0','1','0','0','1','0','1','0','1','1','0','1'}};
ExploreAndLabelColony(grid, 0, 0);
}
private static void ExploreAndLabelColony(char[][] grid, int i, int j)
{
// TODO Auto-generated method stub
if(grid==null)
{
return;
}
if(i==grid.length || j==grid[0].length)
{
return;
}
if (grid[i][j] == '1') //checks if theres a 1 which refers to a colony
{
if (i>0 && i + 1 < grid.length && j>0 && j + 1 < grid[0].length)
{
if (grid[i+1]==grid[j] || grid[i] == grid[j+1] || grid[i-1]==grid[j] || grid[i]==grid[j-1]) //checks if adjacent
{
grid[i][j] = 'A'; //creates a colony
}
}
}
else if(grid[i][j] == '0') //replaces 0 with '-'
{
grid[i][j] = '-';
}
System.out.print(grid[i][j]); //print grid
if(j==grid[0].length-1)
{
System.out.println(); //prints next row
ExploreAndLabelColony(grid,i+1,0); //recurse to increment row
}
ExploreAndLabelColony(grid,i,j+1); //recurse to increment column
}
}
Issues
if (i>0 && i + 1 < grid.length && j>0 && j + 1 < grid[0].length)
{
if (grid[i+1]==grid[j] || grid[i] == grid[j+1] || grid[i-1]==grid[j] || grid[i]==grid[j-1]) //checks if adjacent
{
grid[i][j] = 'A'; //creates a colony
}
}
In the above section of code, j>0 && j + 1 < grid[0].length can not guarantee the access to grid[j].
The check on inner array index can not correctly validate the access to outer array index.
Check adjacent elements
To check adjacent elements, all 4 valid adjacent indices have to be checked
grid[i][j - 1]
grid[i][j + 1]
grid[i - 1][j]
grid[i + 1][j]
In the above 4 checks, please validate the index before making any of the i - 1, i + 1, j - 1, j + 1 access.
For the given cell with coordinates i, j the adjacent elements are in the square:
[i - 1][j - 1], [i - 1][j], [i - 1][j + 1]
[i ][j - 1], CURR_CELL, [i ][j + 1]
[i + 1][j - 1], [i + 1][j], [i + 1][j + 1]
Additional limitations may be applied using Math.min, Math.max functions and adjacent cells can be detected as follows:
if (grid[i][j] == '1') { //checks if theres a 1 which refers to a colony
out: // label to break
for (int ii = Math.max(i - 1, 0), in = Math.min(grid.length, i + 2); ii < in; ii++) {
for (int jj = Math.max(j - 1, 0), jn = Math.min(grid[0].length, j + 2); jj < jn; jj++) {
if (ii == i && jj == j) {
continue; // skip reference cell
}
if (grid[ii][jj] == '1') {
grid[i][j] = 'A';
break out; // as soon as the first neighbor is found
}
}
}
}
With this change, the output for the given input:
public static void main(String[] args) {
char grid[][] = {
{'0','0','0','1','1','0','1','1','0','0','0','1','1','1','0','1','1','1','0','1'},
{'1','0','0','0','0','1','0','0','0','1','0','0','0','0','0','1','1','1','1','1'},
{'0','1','0','0','1','0','0','0','1','0','1','0','0','0','0','0','0','1','1','1'},
{'1','1','1','0','0','1','0','1','0','0','0','0','1','0','1','1','0','1','1','0'},
{'0','1','1','1','0','1','1','1','0','1','0','0','1','0','1','0','1','1','0','1'}
};
ExploreAndLabelColony(grid, 0, 0);
}
is as follows:
---AA-A1---AA1-AAA-A
A----A---A-----AAAAA
-A--A---A-1------AAA
AAA--A-A----A-AA-AA-
-AA1-AA1-1--1-1-A1-1
Possibly, condition should be fixed to check if adjacent cell is already containing A, or if there are too many neighbors but setting/applying these or any other rules is up to the author.
I am trying to find the expected output to the below program..But I am getting the error
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at programbasics.CountingConnections.count(CountingConnections.java:7)
at programbasics.CountingConnections.main(CountingConnections.java:26)
My question is about a matrix m*n. The elements in matrix are populated with values 1 and 0.
1 indicates in establishing connection and 0 indicates Not establishing connection.
we need to connect the available adjacent positions vertically, horizontally and diagonally and count the number of distinct connections established
My piece of code is
package programbasics;
class CountingConnections
{
static int count(int a[][], int i, int j) {
int rows = a.length;
int cols = a[0].length;
if(a[i][j] == 0) return 0;
if (i == rows - 1 && j == cols - 1)
return a[i][j];
else if (i == rows - 1)
return a[i][j + 1];
else if (j == cols - 1)
return a[i + 1][j];
else if (a[i][j] == 1)
return count(a, i + 1, j) + count(a, i, j + 1);
else
return 0;
}
public static void main(String[]args)
{
int a[][] = {{1,0,0,1},
{0,1,1,1},
{1,0,0,1}};
int i = 3;
int j = 4;
System.out.println(count(a, i, j));;
}
}
The expected output is 8. Like the positions are connected as follows
1)(0,0) -> (1,1)
2)(2,0) -> (1,1)
.
.
.
.
8) (0,3) -> (1,3)
It fails to get the expected output 8.
public static int count(int[][] a) {
int[][] paths = new int[a.length][a[0].length];
if ((paths[0][0] = a[0][0]) == 0) {
return 0;
}
for (int c = 1; c < a[0].length; c++) {
paths[0][c] = a[0][c] * paths[0][c - 1];
}
for (int r = 1; r < a.length; r++)
{
paths[r][0] = a[r][0] * paths[r - 1][0];
for (int c = 1; c < a[r].length; c++)
{
paths[r][c] = a[r][c] * (paths[r - 1][c] + paths[r][c - 1]);
}
}
return paths[a.length - 1][a[0].length - 1];
}
public static int count(int[][] a, int m, int n) {
int count = 0;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] == 1) {
if (i - 1 >= 0 && j - 1 >= 0 && a[i - 1][j - 1] == 1) {
count = count + 1;
}
if (i - 1 >= 0 && a[i - 1][j] == 1) {
count = count + 1;
}
if (i - 1 >= 0 && j + 1 < n && a[i - 1][j + 1] == 1) {
count = count + 1;
}
if (j + 1 < n && a[i][j + 1] == 1) {
count = count + 1;
}
}
}
}
return count;
}
You call if(a[i][j] == 0) in your code where you pass 3 as i and 4 as j. However Array's are zero indexed, so when you try to call a[3][4] you are trying to call
0 1 2 3 4
0 {1, 0, 0, 1}
1 {0, 1, 1, 1}
2 {1, 0, 0, 1}
3 X
4
The index where the X is. Clearly this is not a valid index in your Array.
Also your method at different points calls a[i + 1][j] and a[i][j + 1] which means that you will have to take this in account when making sure the code stays in bounds.
As to your actual method your logic seems a bit off. if(a[i][j] == 0) return 0; will return 0 and stop the recursion and return 0 without checking to see if there are any more connections. Your logic should be something more like this:
Start at 0,1.
If the index is a 1
Look one index to the right, one down and to the right (The diagonal) down one, and down one and to the left (The second diagonal).
If any of the numbers at those index's are 1's then up the counter.
Continue to iterate through the matrix, but keep in mind that you are checking one row down and over, so you will only loop until less than length -1 for for both the row and column. Also make sure that you are starting at index a[i][1] as you will be needing to check a[a+1][j-1] and if j == 0 you will be trying to call a[a+1][-1] which will cause another index out of bounds
private int countConnections(int[][] a, int rows, int columns) {
//cartesian plane coordinates around a point
final int[] x = {1, 1, 1, -1, -1, -1, 0, 0};
final int[] y = {1, -1, 0, 1, -1, 0, 1, -1};
int count = 0;
boolean[][] visited = new boolean[rows][columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
for (int k = 0; k < 8; k++) {
int l = i + x[k];
int m = j + y[k];
//check for connections only if the given cell has value 1
if (a[i][j] == 1 && canVisit(l, m, rows, columns, visited) && a[l][m] == 1) {
count++;
}
}
visited[i][j] = true;
}
}
return count;
}
private boolean canVisit(int i, int j, int rows, int columns, boolean [][] visited) {
return i < rows && j < columns && i >= 0 && j >= 0 && !visited[i][j];
}
Check all the 8 cells around a cell whose cell value is 1 and when traversed mark it as visited.
// Counts the neighbors of alive or dead cells in boolean grid.
public static int countNeighbors ( final boolean[][] grid, final int row, final int col ) {
// Finds neighbors in top row.
int count = 0;
for (int i = 1; i > -1; --i) {
if (grid[row - 1][col + i] == true)
count += 1;
else if (grid[row - 1][col + i] == false)
count += 0;
}
// Finds neighbors in same row.
for (int i = 1; i > -1; --i) {
if (grid[row][col + i] == true)
count += 1;
else if (grid[row][col + i] == false)
count += 0;
}
// Finds neighbors in bottom row.
for (int i = 1; i > -1; --i) {
if (grid[row + 1][col + i] == true)
count += 1;
else if (grid[row + 1][col + i] == false)
count += 0;
}
return count;
}
Getting an array out of bounds exception when I attempt to find all true neighbor values in all 8 blocks around the specified square.
I figured the code would already handle if it was out of bounds as I assume those values would be false anyways.
Create a separate function to get the grid cell, including a bounds check:
public static boolean getGridCell ( final boolean[][] grid, final int row, final int col )
{
// bounds check:
if((row < 0) || (row >= grid.length))
return false;
if((col < 0) || (col >= grid[row].length))
return false;
return grid[row][col];
}
Then call this function instead of accessing the grid directly:
public static int countNeighbors ( final boolean[][] grid, final int row, final int col ) {
// Finds neighbors in top row.
int count = 0;
for (int i = 1; i >= -1; --i) {
if (getGridCell(grid, row - 1,col + i))
count += 1;
}
// Finds neighbors in same row.
for (int i = 1; i >= -1; --i) {
if (getGridCell(grid, row, col + i))
count += 1;
}
// Finds neighbors in bottom row.
for (int i = 1; i >= -1; --i) {
if (getGridCell(grid, row + 1, col + i))
count += 1;
}
return count;
}
Also:
There's no need to check if the grid cell is empty and add zero to count if it is, because that isn't going to make any difference to the count.
You don't need to test if(some_boolean == true), you can just write if(some_boolean)
Your loop termination condition should be >= -1 not > -1, if you intend include -1.