multidimensional Flashcards

(41 cards)

1
Q

What is a multi-dimensional array in Java?

A

An array of arrays that represents data in a table-like structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two common types of multi-dimensional arrays?

A
  • 2D arrays
  • 3D arrays
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the primary use of 2D arrays?

A

To store data in grid form or model mathematical matrices

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How are individual elements accessed in a 2D array?

A

Using two indices: arrayName[rowIndex][columnIndex]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a jagged array?

A

An array of arrays where each inner array can have a different length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between rectangular and jagged arrays?

A
  • Rectangular arrays have sub-arrays of the same length
  • Jagged arrays have sub-arrays of different lengths
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the syntax to access an element in a 3D array?

A

arrayName[depthIndex][rowIndex][columnIndex]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What key structures do multi-dimensional arrays in Java not implement?

A

True multi-dimensional arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In Java, how is a 2D array stored in memory?

A

As an array of arrays where each row is stored separately in memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are common use cases for 2D arrays?

A
  • Tabular data storage
  • Matrix operations
  • Game boards
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the memory layout of a 1D array?

A

Stored as a contiguous block of memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you declare a 2D array in Java?
Syntax

A

int[][] arr2D = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a key point for traversing multi-dimensional arrays?

A

Use nested loops

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True or False: A 3D array is an array of arrays of arrays.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is static initialization in multi-dimensional arrays?

A

Initialization with predefined values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is dynamic initialization in multi-dimensional arrays?

A

Initialization when values are calculated or assigned during runtime

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What analogy can be used to explain multi-dimensional arrays?

A

A spreadsheet with rows and columns

18
Q

What indexing method is used for traversing a 2D array?

A

Two loops, one for rows and one for columns

19
Q

What is the difference in memory structure between a 2D array and a 3D array?

A

A 2D array points to an array of 1D arrays, while a 3D array points to an array of 2D arrays

20
Q

Fill in the blank: In a jagged array, each row can have a different number of ______.

21
Q

What are matrix operations that can be performed using 2D arrays?

A
  • Addition
  • Subtraction
22
Q

What does the term ‘nested loops’ refer to in the context of multi-dimensional arrays?

A

Loops within loops used for traversing arrays

23
Q

What is the main reference variable in a 3D array?

A

The main array holds references to the 2D arrays

24
Q

What is the memory addressing example for a 2D array?

A

[address1] -> [1, 2, 3], [address2] -> [4, 5, 6], [address3] -> [7, 8, 9]

25
What are matrix addition and subtraction?
Common operations performed using 2D arrays in mathematics and computer graphics.
26
How are matrix addition and subtraction performed?
By adding or subtracting corresponding elements in two matrices.
27
What are the use cases for 2D arrays?
* Storing tabular data (student grades, sales data) * Performing matrix operations (addition, subtraction) * Game boards (chess, tic-tac-toe)
28
What are 3D arrays used for?
* Representing 3D grids (used in games or simulations) * Multi-layered matrices (multiple 2D matrices stacked together) * Scientific simulations (e.g., fluid dynamics)
29
What is a voxel?
A 3D pixel, like a tiny cube that represents a block of space.
30
What does a voxel grid represent?
A 3D array of voxels that form a 3D object or environment.
31
What is the structure of a voxel grid?
A 3x3x3 grid with three layers, each layer having 3 rows and 3 columns.
32
How are values filled in a voxel grid?
Using nested loops to fill the grid with values (like color codes).
33
What are best practices for array initialization?
Always initialize your array with the correct dimensions for proper memory allocation.
34
What is dynamic initialization of arrays?
Initializing the array based on user input or calculations when the size is unknown at the start.
35
Why use meaningful variable names for arrays?
To improve clarity and understanding of the array's purpose.
36
What is the issue with hardcoding array sizes?
It reduces flexibility; using variables or constants is preferred.
37
What is an efficient practice when using nested loops?
Avoid calculating the array length inside the loop; store it in a variable before the loop.
38
When should a for-each loop be used?
When exact indices are not needed, as it improves readability.
39
What are jagged arrays?
Arrays where the layers do not need to have the same number of rows and columns.
40
What is boundary checking in array testing?
Ensuring that you do not access an out-of-bounds index to avoid ArrayIndexOutOfBoundsException.
41
What debugging tools can be used for arrays?
Print statements or debugging tools to check values of indices and array elements during execution.