zuai-logo

What is row-major traversal?

Traversing a 2D array by processing all elements in one row before moving to the next row.

Flip to see [answer/question]
Flip to see [answer/question]

All Flashcards

What is row-major traversal?

Traversing a 2D array by processing all elements in one row before moving to the next row.

What is column-major traversal?

Traversing a 2D array by processing all elements in one column before moving to the next column.

What are nested for loops?

A for loop inside another for loop, commonly used to iterate over 2D arrays.

What is an enhanced for loop?

A simplified for loop syntax for iterating through elements of an array or collection.

What is a 2D array?

An array of arrays, where each element is itself an array, forming rows and columns.

Define linear search.

A method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all elements have been searched.

Define pass-by-value.

A method of argument passing in which a copy of the actual parameter's value is made and passed to the called function or method.

What is autoboxing?

The automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes.

Define mode.

The value that appears most often in a set of data.

Define mean.

The average of a set of numbers.

What does the following code output?

java
int[][] arrayB = {{1, 2}, {3, 4}};
for (int i = 0; i < arrayB.length; i++) {
  for (int j = 0; j < arrayB[0].length; j++) {
    System.out.print(arrayB[i][j] + " ");
  }
}

1 2 3 4

What does the following code output?

java
int[][] arrayB = {{1, 2}, {3, 4}};
for (int i = 0; i < arrayB[0].length; i++) {
  for (int j = 0; j < arrayB.length; j++) {
    System.out.print(arrayB[j][i] + " ");
  }
}

1 3 2 4

Identify the error in the following code:

java
public static void main(str[] args) {
  int[][] arrayB = {{1, 2}, {3, 4}};
  rowWiseForward(arrayB);
}

The parameter in main should be String[], not str[].

What does the following code output?

java
int[][] arrayB = {{1, 2}, {3, 4}};
int sum = 0;
for (int[] row : arrayB) {
  for (int num : row) {
    sum += num;
  }
}
System.out.println(sum);

10

What does the following code output?

java
int[][] arrayB = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
System.out.println(arrayB.length);

3

What does the following code output?

java
int[][] arrayB = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
System.out.println(arrayB[0].length);

4

What does the following code output?

java
int[][] arrayB = {{1, 2}, {3, 4}};
System.out.println(arrayB[1][0]);

3

What does the following code output?

java
int[][] arrayB = {{1, 2}, {3, 4}};
int product = 1;
for (int i = 0; i < arrayB.length; i++) {
  for (int j = 0; j < arrayB[0].length; j++) {
    product *= arrayB[i][j];
  }
}
System.out.println(product);

24

What does the following code output?

java
int[][] arrayB = {{1, 2}, {3, 4}};
int max = arrayB[0][0];
for (int i = 0; i < arrayB.length; i++) {
  for (int j = 0; j < arrayB[0].length; j++) {
    if (arrayB[i][j] > max) {
      max = arrayB[i][j];
    }
  }
}
System.out.println(max);

4

What does the following code output?

java
int[][] arrayB = {{1, 2, 3}, {4, 5, 6}};
int count = 0;
for (int[] row : arrayB) {
  for (int num : row) {
    if (num % 2 == 0) {
      count++;
    }
  }
}
System.out.println(count);

3

How is 2D array traversal applied in image processing?

Iterating through pixels to apply filters, transformations, or analysis.

How is 2D array traversal applied in game development?

Navigating game boards, processing tile-based maps, or managing game entities in a grid.

How is 2D array traversal applied in spreadsheet software?

Processing data in rows and columns for calculations, sorting, and filtering.

How is finding a sum applied in image processing?

Calculating the average color value of an image.

How is finding the mode applied?

Determining the most frequent value in a dataset.