How is an element at row 'i' and column 'j' typically accessed in a 2D array named 'matrix'?
matrix[i][j]
matrix[i, j]
matrix(i)[j]
matrix.get(i, j)
What is a key difference between a 1D array and a 2D array?
1D arrays represent linear sequences, 2D arrays represent tabular data.
1D arrays are static in size, 2D arrays can change size dynamically.
1D arrays store numbers while 2D arrays store characters.
1D arrays can only be accessed sequentially, 2D arrays allow random access.
Consider a 2D array storing characters to represent a word search grid. You want to check if a given word exists in the grid horizontally or vertically. Which algorithm would be suitable for this task?
Binary Search
Bubble Sort
Depth First Search (DFS)
Quick Sort
What is the time complexity of accessing an element in a 2D array with 'm' rows and 'n' columns?
O(1)
O(m + n)
O(log m + log n)
O(m * n)
You want to find the first occurrence of a specific element in a sorted array. Which search algorithm is the most efficient?
Both are equally efficient in this case.
It depends on the size of the array.
Linear Search
Which of the following is a valid array declaration in a common programming language (syntax may vary slightly)?
int numbers[] = {1, 2, 3, 4};
numbers = array(1, 2, 3, 4);
array numbers = [1, 2, 3, 4];
All of the above.
Accessing an element outside the valid index range of an array leads to what kind of error?
SyntaxError
IndexError or OutOfBounds exception
ValueError
TypeError
What is the time complexity of finding the maximum element in a sorted array?
O(n log n)
O(log n)
O(n)
Which of the following sorting algorithms has the best average-case time complexity?
Insertion Sort
Selection Sort
Merge Sort
Imagine a 2D array representing a grayscale image. Each element holds a pixel intensity value. How would you swap two rows 'r1' and 'r2' in this array?
Iterate through columns, swapping elements at 'image[r1][j]' and 'image[r2][j]' for each column 'j'.
Directly assign 'image[r1]' to 'image[r2]' and vice-versa.
Create a new 2D array with the swapped rows.
Swapping rows is not possible in a 2D array.