Implementing 2D Array Algorithms - AP Computer Science A
Card 1 of 30
What is the best way to find the sum of a specific column?
What is the best way to find the sum of a specific column?
Tap to reveal answer
Iterate over rows, sum the specific column. Access same column index across all rows and accumulate.
Iterate over rows, sum the specific column. Access same column index across all rows and accumulate.
← Didn't Know|Knew It →
What happens when you try to access array[0][10] in a 2D array?
What happens when you try to access array[0][10] in a 2D array?
Tap to reveal answer
ArrayIndexOutOfBoundsException. Index 10 exceeds array bounds, throwing runtime exception.
ArrayIndexOutOfBoundsException. Index 10 exceeds array bounds, throwing runtime exception.
← Didn't Know|Knew It →
What is the purpose of array[0].length in a 2D array?
What is the purpose of array[0].length in a 2D array?
Tap to reveal answer
To get the number of columns in the first row. Determines column count for the first row dimension.
To get the number of columns in the first row. Determines column count for the first row dimension.
← Didn't Know|Knew It →
Identify the method to fill a 2D array with random values.
Identify the method to fill a 2D array with random values.
Tap to reveal answer
Use nested loops with Math.random(). Generate random numbers and assign to each array position.
Use nested loops with Math.random(). Generate random numbers and assign to each array position.
← Didn't Know|Knew It →
What is the consequence of not initializing a 2D array?
What is the consequence of not initializing a 2D array?
Tap to reveal answer
NullPointerException on access. Uninitialized array references are null, causing access errors.
NullPointerException on access. Uninitialized array references are null, causing access errors.
← Didn't Know|Knew It →
What is the syntax to initialize a 2D array with specific values in Java?
What is the syntax to initialize a 2D array with specific values in Java?
Tap to reveal answer
int[][] array = {{1, 2, 3}, {4, 5, 6}};. Nested braces define rows and columns with literal values.
int[][] array = {{1, 2, 3}, {4, 5, 6}};. Nested braces define rows and columns with literal values.
← Didn't Know|Knew It →
How do you initialize a 2D array with 3 rows and 4 columns?
How do you initialize a 2D array with 3 rows and 4 columns?
Tap to reveal answer
int[][] array = new int[3][4];. Creates array with specified row and column dimensions.
int[][] array = new int[3][4];. Creates array with specified row and column dimensions.
← Didn't Know|Knew It →
What does array[1] refer to in a 2D array?
What does array[1] refer to in a 2D array?
Tap to reveal answer
The entire second row. Returns reference to the one-dimensional array at index 1.
The entire second row. Returns reference to the one-dimensional array at index 1.
← Didn't Know|Knew It →
How do you find the number of columns in the first row?
How do you find the number of columns in the first row?
Tap to reveal answer
array[0].length. Access length property of any row to get column count.
array[0].length. Access length property of any row to get column count.
← Didn't Know|Knew It →
What is the output of array.length for int[][] array = new int[4][5]?
What is the output of array.length for int[][] array = new int[4][5]?
Tap to reveal answer
- Length property returns number of rows in the 2D array.
- Length property returns number of rows in the 2D array.
← Didn't Know|Knew It →
How do you print all elements of a 2D array?
How do you print all elements of a 2D array?
Tap to reveal answer
Use nested loops to iterate and print elements. Outer loop handles rows, inner loop handles columns for display.
Use nested loops to iterate and print elements. Outer loop handles rows, inner loop handles columns for display.
← Didn't Know|Knew It →
Identify the method to sum all elements in a 2D array.
Identify the method to sum all elements in a 2D array.
Tap to reveal answer
Use nested loops to iterate and sum elements. Accumulate values using nested iteration through all elements.
Use nested loops to iterate and sum elements. Accumulate values using nested iteration through all elements.
← Didn't Know|Knew It →
What is the result of accessing array[-1][0]?
What is the result of accessing array[-1][0]?
Tap to reveal answer
ArrayIndexOutOfBoundsException. Negative indices are invalid and throw runtime exception.
ArrayIndexOutOfBoundsException. Negative indices are invalid and throw runtime exception.
← Didn't Know|Knew It →
What is the syntax to declare a 2D array with predefined values?
What is the syntax to declare a 2D array with predefined values?
Tap to reveal answer
int[][] array = {{1, 2}, {3, 4}};. Initializer lists create and populate array in one statement.
int[][] array = {{1, 2}, {3, 4}};. Initializer lists create and populate array in one statement.
← Didn't Know|Knew It →
What is the time complexity to access an element in a 2D array?
What is the time complexity to access an element in a 2D array?
Tap to reveal answer
$O(1)$. Direct access by indices provides constant time complexity.
$O(1)$. Direct access by indices provides constant time complexity.
← Didn't Know|Knew It →
Which option describes a jagged array?
Which option describes a jagged array?
Tap to reveal answer
Rows can have different lengths. Unlike rectangular arrays, each row can have different column count.
Rows can have different lengths. Unlike rectangular arrays, each row can have different column count.
← Didn't Know|Knew It →
How do you transpose a 2D array?
How do you transpose a 2D array?
Tap to reveal answer
Swap rows with columns. Transform rows into columns and columns into rows.
Swap rows with columns. Transform rows into columns and columns into rows.
← Didn't Know|Knew It →
What is the key difference between 2D arrays and arrays of arrays?
What is the key difference between 2D arrays and arrays of arrays?
Tap to reveal answer
Arrays of arrays can be jagged; 2D arrays are rectangular. Array of arrays allows variable row sizes, 2D arrays are fixed.
Arrays of arrays can be jagged; 2D arrays are rectangular. Array of arrays allows variable row sizes, 2D arrays are fixed.
← Didn't Know|Knew It →
What is the syntax to copy a row of a 2D array?
What is the syntax to copy a row of a 2D array?
Tap to reveal answer
Use System.arraycopy or a loop. Built-in method or manual iteration copies row elements.
Use System.arraycopy or a loop. Built-in method or manual iteration copies row elements.
← Didn't Know|Knew It →
Identify the method to find the maximum element in a 2D array.
Identify the method to find the maximum element in a 2D array.
Tap to reveal answer
Iterate and compare each element. Track maximum value while traversing all array elements.
Iterate and compare each element. Track maximum value while traversing all array elements.
← Didn't Know|Knew It →
What is the result of array[0][5] if array has 4 columns?
What is the result of array[0][5] if array has 4 columns?
Tap to reveal answer
ArrayIndexOutOfBoundsException. Index 5 exceeds valid column range, causing runtime error.
ArrayIndexOutOfBoundsException. Index 5 exceeds valid column range, causing runtime error.
← Didn't Know|Knew It →
How do you set all elements in the first row to 0?
How do you set all elements in the first row to 0?
Tap to reveal answer
Use a loop: for (int i = 0; i < array[0].length; i++) array[0][i] = 0;. Loop through first row indices and assign zero values.
Use a loop: for (int i = 0; i < array[0].length; i++) array[0][i] = 0;. Loop through first row indices and assign zero values.
← Didn't Know|Knew It →
What is the length property of a 2D array in Java?
What is the length property of a 2D array in Java?
Tap to reveal answer
Number of rows (array.length). Returns the number of rows, not total elements.
Number of rows (array.length). Returns the number of rows, not total elements.
← Didn't Know|Knew It →
How can you set the element at row 1, column 2 to 5?
How can you set the element at row 1, column 2 to 5?
Tap to reveal answer
array[1][2] = 5;. Assignment operator sets value at specific row-column position.
array[1][2] = 5;. Assignment operator sets value at specific row-column position.
← Didn't Know|Knew It →
What is a 2D array in Java?
What is a 2D array in Java?
Tap to reveal answer
A grid of elements stored in rows and columns. Arrays organized in row-column structure for storing tabular data.
A grid of elements stored in rows and columns. Arrays organized in row-column structure for storing tabular data.
← Didn't Know|Knew It →
How do you declare a 2D array of integers in Java?
How do you declare a 2D array of integers in Java?
Tap to reveal answer
int[][] array;. Double brackets indicate two dimensions for row and column indices.
int[][] array;. Double brackets indicate two dimensions for row and column indices.
← Didn't Know|Knew It →
Which option describes a jagged array?
Which option describes a jagged array?
Tap to reveal answer
Rows can have different lengths. Unlike rectangular arrays, each row can have different column count.
Rows can have different lengths. Unlike rectangular arrays, each row can have different column count.
← Didn't Know|Knew It →
What is the syntax to declare a 2D array with predefined values?
What is the syntax to declare a 2D array with predefined values?
Tap to reveal answer
int[][] array = {{1, 2}, {3, 4}};. Initializer lists create and populate array in one statement.
int[][] array = {{1, 2}, {3, 4}};. Initializer lists create and populate array in one statement.
← Didn't Know|Knew It →
What is the index of the last column in a 2D array with 5 columns?
What is the index of the last column in a 2D array with 5 columns?
Tap to reveal answer
- Last index is always length minus one in zero-based indexing.
- Last index is always length minus one in zero-based indexing.
← Didn't Know|Knew It →
How do you iterate over all elements in a 2D array using nested loops?
How do you iterate over all elements in a 2D array using nested loops?
Tap to reveal answer
Use two nested for loops. Outer loop for rows, inner loop for columns traverses all elements.
Use two nested for loops. Outer loop for rows, inner loop for columns traverses all elements.
← Didn't Know|Knew It →