Free Online Flashcard Deck

Java 2D Arrays: Traversal and Grid Algorithms Free Online FlashCards

Study Java 2D Arrays: Traversal and Grid Algorithms with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is a Java 2D array?

Back

A Java 2D array is an array whose elements are themselves arrays. The first index selects the row, and the second selects the column.

02
Front

How do you find 2D-array dimensions?

Back

For scores, scores.length gives the number of rows, while scores[row].length gives the number of columns in that specific row.

03
Front

What does new int[3][4] create?

Back

new int[3][4] creates three rows with four integer elements per row. Each element initially contains 0.

04
Front

What does scores[2][1] identify?

Back

In a rectangular array, scores[2][1] refers to row 2, column 1. With zero-based indexing, this is the third row and second column.

05
Front

What is row-major traversal?

Back

Row-major traversal processes every element of row 0, then every element of row 1, continuing through the final row.

06
Front

What order does column-major traversal use?

Back

For grid = {{1, 2, 3}, {4, 5, 6}}, column-major order visits 1, 4, 2, 5, 3, 6.

07
Front

Which bound should traverse a row safely?

Back

The inner loop should use col < data[row].length. This uses the current row's column count instead of assuming rows and columns are equal.

08
Front

How does rowSum process one row?

Back

A row sum fixes the row index and varies the column index: for (int col = 0; col < data[row].length; col++) sum += data[row][col].

09
Front

How does columnSum process one column?

Back

A column sum fixes the column index and varies the row index: for (int row = 0; row < data.length; row++) sum += data[row][col].

10
Front

Why does a 2D-array average need a double cast?

Back

Cast the sum to double before division, as in (double) sum / count. Otherwise, integer division can discard the fractional part.

11
Front

How should a maximum search be initialized?

Back

Initialize max with data[0][0], not 0. This works even when every array value is negative.

12
Front

What is short-circuiting in a 2D-array search?

Back

A search for any matching element can return immediately when the condition is true. For example, containsNegative returns true at the first value below 0, then returns false if none is found.