AP CSA 2D arrays key terms

Key terms and concepts related to 2D arrays in AP Computer Science A.

Pixel19·19 fiches·18 questions
APcomputer_scienceprogramming
0
Je sais
1 / 19
0
J'apprends
Recto

What is a 2D array?

Appuyez pour retourner
Verso

An array of arrays, like a matrix, where each element is accessed by two indices.

Appuyez pour retourner
Je sais
J'apprends

Quiz(18 questions)

Question 1 sur 18

1. What does `array.length` return for a 2D array?

Termes dans ce set(19)

What is a 2D array?

An array of arrays, like a matrix, where each element is accessed by two indices.

Accessing an element

To access an element in a 2D array, use syntax: `array[row][column]`.

True or false: A 2D array can have different row sizes.

False, because all rows in a 2D array must have the same length.

Difference between row-major and column-major order.

Row-major stores rows in contiguous memory, while column-major stores columns.

How to initialize a 2D array?

Use `int[][] array = new int[rows][columns];` to create it.

What is the length of a 2D array?

Use `array.length` for rows and `array[0].length` for columns.

Fill in the blank: The first index in a 2D array represents the ___ .

row number.

What is a common use of 2D arrays?

Storing data in grid-like structures, such as game boards or matrices.

True or false: You can change the size of a 2D array after creation.

False, because arrays have fixed sizes in Java.

How do you iterate through a 2D array?

Use nested loops: `for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) { ... }}`.

What is the maximum index for a 2D array with 3 rows and 4 columns?

Row index: 2, Column index: 3, since indexing starts at 0.

Define a jagged array.

An array of arrays where each sub-array can have different lengths.

Difference between a 1D array and a 2D array.

A 1D array is linear, while a 2D array represents data in two dimensions.

Fill in the blank: 2D arrays are often used in ___ algorithms.

graph traversal or image processing.

What is an example of a 2D array declaration?

int[][] matrix = { {1, 2}, {3, 4} };

True or false: You can use a for-each loop with a 2D array.

True, because each row can be iterated over like a 1D array.

What will `array[1][2]` access?

The element in the second row and third column of the array.

How to copy a 2D array?

Use nested loops to copy elements, as arrays cannot be directly copied.

Explain a common error with 2D arrays.

Accessing an index out of bounds, leading to an `ArrayIndexOutOfBoundsException`.

Questions dans ce set(18)

1. What does `array.length` return for a 2D array?

A.Number of rows
B.Number of columns
C.Total elements
D.None of the above

2. Which of the following correctly accesses the first element of the second row?

A.array[1][0]
B.array[0][1]
C.array[2][1]
D.array[1, 0]

3. Which statement about jagged arrays is true?

A.All rows have the same length
B.Rows can have different lengths
C.It's a 2D array
D.Both B and C

4. Which of the following is NOT a valid 2D array initialization?

A.int[][] arr = new int[2][3];
B.int arr[][] = {{1,2},{3,4}};
C.int[][] arr = new int[2];
D.int[][] arr = new int[2][2];

5. Which method is used to copy elements from a 2D array?

A.System.arraycopy()
B.clone()
C.for-each loop
D.None of the above

6. How is a 2D array represented in memory?

A.As a single contiguous block
B.As two separate blocks
C.In row-major order
D.Both A and C

7. To access the value at the last row and last column in a matrix with 4 rows and 5 columns, what indices are used?

A.4, 5
B.3, 4
C.0, 0
D.5, 4

8. What will happen if you try to access `array[2][3]` in a 2D array of size 2x3?

A.Return a default value
B.Throw an exception
C.Return null
D.None of the above

9. Which of the following describes a row-major order?

A.Rows stored one after the other
B.Columns stored one after the other
C.Both rows and columns mixed
D.Only first column stored

10. When iterating a 2D array, what is necessary for the inner loop?

A.Use the same index for both loops
B.Use the second index correctly
C.Use a decrementing loop
D.None of the above

11. In Java, how do you declare a 2D array?

A.int[][] arr = new int[5][5];
B.int arr[][] = new int[5];
C.2D int arr;
D.int arr(5, 5);

12. What does `array[i][j]` represent in a 2D array?

A.The element in row i, column j
B.The element in column i, row j
C.The total number of elements
D.None of the above

13. True or false: 2D arrays can only hold primitive data types.

A.True
B.False
C.Depends on the array size
D.None of the above

14. Which of the following is an example of a jagged array?

A.int[][] arr = new int[3][3];
B.int[][] arr = { {1}, {2, 3}, {4, 5, 6} };
C.int arr[] = new int[5];
D.int arr[][] = { {} };

15. What will the expression `array.length` return for a two-dimensional array?

A.Total number of elements
B.Number of rows
C.Number of columns
D.Size of the first row

16. What happens if you declare a 2D array without assigning a size?

A.It works fine
B.It causes a compile error
C.It's initialized to 0
D.None of the above

17. How can you represent a chessboard using a 2D array?

A.int[][] chessboard = new int[8][8];
B.int chessboard[8][8];
C.int chessboard[] = {{} };
D.None of the above

18. Which statement is correct about 2D array size?

A.Fixed after creation
B.Can be changed
C.Only rows can vary
D.None of the above

Sets associés

Créez votre propre set d'étude

Téléchargez un PDF, collez vos notes ou décrivez un sujet – l'IA génère des fiches, des quiz et plus en quelques secondes.

Mis en avant sur