1/25
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
2D Array
An array of arrays, visualized as a grid or table with rows and columns.
Declaring a 2D Array
Using the syntax: type[][] name = new type[rows][cols]; to specify dimensions.
Default Value for int in 2D Array
The default value for uninitialized integers in a 2D array is 0.
Accessing Elements in a 2D Array
Elements are accessed using row-major indices, denoted as arrayName[row][col].
Row-Major Traversal
A method of processing a 2D array row by row.
Column-Major Traversal
A method of processing a 2D array column by column.
Enhanced For-Loop
A read-only loop structure for traversing 2D arrays without index positions.
Linear Search in 2D arrays
A method to find a specific value by checking each element in the grid.
Validating Index Boundaries for Neighbors
Ensure indices are within valid range to avoid ArrayIndexOutOfBoundsException.
Traversing Rectangular Areas
Processing a specific portion of the 2D array instead of the whole.
arr.length vs. arr[0].length
arr.length returns the number of rows, while arr[0].length returns the number of columns.
Common Mistake: Using arr.length in Inner Loops
Not recognizing arr[0].length should be used for column limits.
Confusing Row and Column Indices
In a 2D array, the first index is for rows (vertical), the second is for columns (horizontal).
Out of Bounds Access
Attempting to access an index beyond array limits, which results in exceptions.
Mutating Array Elements with For-Each Loops
The for-each loop does not allow direct modification of the array's elements.
Using Initializer Lists for 2D Arrays
Declaring and populating a 2D array by specifying values directly upon creation.
Syntax for Declaring a 2D Array in Java
int[][] matrix = new int[3][4]; creates a 2D array with 3 rows and 4 columns.
Processing 2D Array with Nested Loops
To iterate through all elements, use an outer loop for rows and an inner loop for columns.
Neighbor Checking in Grid Algorithms
In algorithms like Game of Life, check surrounding cells carefully to avoid exceptions.
Sum of a 2x2 Section
An example of traversing only a subsection of a 2D array for calculations.
Row Index vs. Column Index
Row index refers to the vertical position, while column index refers to the horizontal position.
The Role of the Outer Loop in 2D Traversals
The outer loop iterates through either rows or columns based on the traversal method.
Limit Changes in Column-Major Traversal
The outer and inner loops are swapped compared to row-major traversal.
Default values for boolean in 2D Array
The default value for uninitialized booleans in a 2D array is false.
Common Pitfall: Incorrect Neighbors Access
Failing to check boundaries before accessing neighbors can lead to runtime errors.
Memory Representation of 2D Arrays
2D arrays are stored in memory as a single-dimensional array of references.