multidimensional Flashcards
(41 cards)
What is a multi-dimensional array in Java?
An array of arrays that represents data in a table-like structure
What are the two common types of multi-dimensional arrays?
- 2D arrays
- 3D arrays
What is the primary use of 2D arrays?
To store data in grid form or model mathematical matrices
How are individual elements accessed in a 2D array?
Using two indices: arrayName[rowIndex][columnIndex]
What is a jagged array?
An array of arrays where each inner array can have a different length
What is the difference between rectangular and jagged arrays?
- Rectangular arrays have sub-arrays of the same length
- Jagged arrays have sub-arrays of different lengths
What is the syntax to access an element in a 3D array?
arrayName[depthIndex][rowIndex][columnIndex]
What key structures do multi-dimensional arrays in Java not implement?
True multi-dimensional arrays
In Java, how is a 2D array stored in memory?
As an array of arrays where each row is stored separately in memory
What are common use cases for 2D arrays?
- Tabular data storage
- Matrix operations
- Game boards
What is the memory layout of a 1D array?
Stored as a contiguous block of memory
How do you declare a 2D array in Java?
Syntax
int[][] arr2D = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
What is a key point for traversing multi-dimensional arrays?
Use nested loops
True or False: A 3D array is an array of arrays of arrays.
True
What is static initialization in multi-dimensional arrays?
Initialization with predefined values
What is dynamic initialization in multi-dimensional arrays?
Initialization when values are calculated or assigned during runtime
What analogy can be used to explain multi-dimensional arrays?
A spreadsheet with rows and columns
What indexing method is used for traversing a 2D array?
Two loops, one for rows and one for columns
What is the difference in memory structure between a 2D array and a 3D array?
A 2D array points to an array of 1D arrays, while a 3D array points to an array of 2D arrays
Fill in the blank: In a jagged array, each row can have a different number of ______.
columns
What are matrix operations that can be performed using 2D arrays?
- Addition
- Subtraction
What does the term ‘nested loops’ refer to in the context of multi-dimensional arrays?
Loops within loops used for traversing arrays
What is the main reference variable in a 3D array?
The main array holds references to the 2D arrays
What is the memory addressing example for a 2D array?
[address1] -> [1, 2, 3], [address2] -> [4, 5, 6], [address3] -> [7, 8, 9]