Double Dimensional Arrays Flashcards

1
Q

What is a 2D Array?

A

It is an array of arrays and it stores data in rows and columns (tabular format).

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

Elements can be accessed through using two indices which is?

A

row index and column index.

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

What is the other name of 2D dimensional?

A

multidimensional arrays

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

What is a data structure commonly used in mathematics to represent matrices and complex data structures?

A

2D Array

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

When a 2D Array is created, Java first creates a 1D array that contains _________ (pointers) to other 1D arrays, which represent the ___ of the 2D array.

A

references, rows

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

How are the rows of a 2D array stored in Java?

A

Each row in a 2D array is stored as a separate 1D array, and the main array contains pointers to these individual row arrays.

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

How many indices are required to access an element in a 2D array in Java?

A

A 2D array in Java requires two indices:
* One for the row
* One for the column

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

How do you initialize a 2D array in Java with specific values?

A

A 2D array can be initialized using curly braces {} with nested arrays:

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

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

How do you declare a 2D array in Java?

A

Declared using the following syntax:
dataType[][] arrayName;

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

What are the ways to initialize a 2D Array

A
  1. Static Initialization
  2. Dynamic Initialization
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Set the size first, then assign values later

A

Dynamic Initialization

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

Assign values directly during declaration.

A

Static Initialization

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

What happens when only the number of rows is specified while declaring a 2D array in Java?

A

The columns remain uninitialized, creating a jagged array where each row can have a different number of columns.

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

A ____ array is useful for storing ____________ , such as words of different lengths, lists of varying sizes, or ____________.

A

jagged, flexible data structures, irregularly shaped matrices

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

Why must the number of rows be specified first when creating a 2D array in Java?

A

In Java, a 2D array is an array of 1D arrays, so the number of rows must be specified first to allocate space for row references before defining column sizes.

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

What happens when a 2D array is declared without initializing rows or columns in Java?

A

It only creates a reference without allocating memory. The array must be initialized before use.

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

How do you declare a 2D array in Java without initializing its size?

A

You can declare a 2D array like this:
int[][] matrix;

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

This is capable of storing images, text, and other types of data, and is useful for data analysis and visualization?

A

2D Array

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

Specify the number of rows but leave columns uninitialized.

A

Double-Dimensional Array with Only Rows Initialized

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

What is a jagged Array?

A

is a 2D array where each row can have a different number of columns.

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

You must define rows first because a 2D array is an array of arrays.

A

Double-Dimensional Array with Only Columns Initialized

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

This type of array can declare a 2D array without initializing rows or columns.

A

Double-Dimensional Array with No Rows or Columns Initialized

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

This is just a reference; no memory is allocated yet and must be initialize before use.

A

Double-Dimensional Array with No Rows or Columns Initialized

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

This type of array can declare a 2D array without initializing rows or columns.

A

Double-Dimensional Array with No Rows or Columns Initialized

25
Q

Where do 2D arrays are usually stored?

A

Often stored in memory as 1D arrays.

26
Q

What are the 2 common methods for storing 2D array data?

A

*Row-Major Order.
*Column-Major Order.

27
Q

How does Row-Major Order work?

A

All elements of the first row are stored consecutively. Followed by all elements of the second row, and so on.

28
Q

What type languages that uses Row-Major Order?

A

Used in languages like C, C++, and Java.

29
Q

In Row-Major Order, Elements are stored ______ by _____ in memory.

A

row by row

30
Q

How does Column-Major Order work?

A

All elements of the first column are stored consecutively. Followed by all elements of the second column, and so on.

31
Q

In Column-Major Order, Elements are stored ______ by _____ in memory.

A

column by column

32
Q

What type languages that uses Column-Major Order?

A

Used in languages like Fortran, MATLAB, and R.

33
Q

What are the key major differences between Row-Major and Column-Major?

A

Row-Major fills rows first, while Column-Major fills columns first

34
Q

Arrays are stored in contiguous ________ ________.

A

memory locations

35
Q

Elements are accessed using ______ _______.

A

numeric indexing

36
Q

What is the syntax for accessing elements?

A

DataType var = ArrayName[i][j]

37
Q

What is a heterogeneous 2D array?

A

Where each row can store different data types.

38
Q

What does homogenous mean in 2D Array?

A

Homogeneous means that all elements in an array must be of the same data type.

39
Q

What does Heterogeneity mean in 2D Array?

A

The presence of different types or variations within a group.

40
Q

Java arrays are ________ by _______(all elements must be of the same type).

A

homogeneous, default

41
Q

How can heterogeneity be achieved in a Java 2D array?

A

It can be achieved by using the Object class, which is the root of Java’s class hierarchy. By declaring a 2D array as Object[][], we can store elements of different data types.

42
Q

How do you declare and initialize a heterogeneous 2D array in Java?

A

Use Object[][], which allows storing different data types.

43
Q

How to access 2D Array Elements?

A

You must cast(typecasting) elements back to their original types when accessing them.

44
Q

Arrays know their ______ (how many elements they can store).

45
Q

The _______ is a public ______
so you can use _______ to access the field (arrayName.length).

A

length, read-only field, dot-notation

46
Q

Gives the number of rows in the 2D array.

A

numbers.length

47
Q

square matrix

A

(rows = columns)

48
Q

Gives the number of columns in the first row.

A

numbers[0].length

49
Q

What type of Loop to use in 2D Array?

A

nested loops

50
Q

What does traverse mean in 2D Array?

A

Traverse means to go through or visit each element of a data structure one by one.

51
Q

What are the Key points when using Row-Major and Colum-Major?

A

Row-Major Order:
*More efficient in Java.
*Outer loop iterates over rows, inner loop
iterates over columns.

Column-Major Order:

*Useful for specific use cases.
*Outer loop iterates over columns, inner loop iterates over rows.

52
Q

Enhanced For Loop with 2D Arrays Uses ________ and always iterates in ______ order.

A

nested enhanced for loops, row-major

53
Q

When using enhanced for loop. The out loop access the ____ as an _____. While the Inner loop access each _________ in the row.

A

row, array, element

54
Q

What are the common mistakes/issues with 2D Arrays?

A
  • Incorrect Array Indexing
  • Assuming Rectangular Arrays
  • Forgetting to Initialize Rows
  • Confusing Row-Major and Column-Major Order
55
Q

A double-dimensional (2D) array is a ________ that stores elements in a ______ format with rows and columns, allowing for the organization of data in a _______ manner.

A

data structure, tabular, grid-like

56
Q

In Java, a 2D array is essentially an _________, where each row is a _________ array, and elements are accessed using ________: one for the row and one for the column.

A

array of arrays, one-dimensional, two indices

57
Q

2D arrays can be ________ (all rows have the same number of columns) or _______ (rows can have varying lengths).

A

rectangular, jagged

58
Q

They are commonly used to represent matrices, tables, or grids in applications like _________, _________, and _________.

A

image processing, game development, data analysis

59
Q

Key operations include _______ , _______ (statically or dynamically), _______ (using nested loops in row- major or column-major order), and _______ elements using indices.

A

declaration, initialization, traversal, accessing