What is the primary advantage of using binary search over linear search?
Binary search is generally faster for large arrays.
Binary search works on unsorted arrays.
Binary search uses less memory.
Binary search is simpler to implement.
What is the space complexity of storing a 2D array with 'm' rows and 'n' columns?
O(1)
O(n)
O(m * n)
O(m)
What is the time complexity of accessing an element in a 2D array with 'm' rows and 'n' columns?
O(log m + log n)
O(m + n)
Which code snippet correctly initializes a 2D array named 'grid' with 3 rows and 4 columns, all filled with zeros?
int grid[3][4] = {0};
int grid[3][4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int grid[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) grid[i][j] = 0;
int grid[3][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
Which sorting algorithm works by repeatedly selecting the minimum element and placing it in its correct position?
Bubble Sort
Selection Sort
Quick Sort
Merge Sort
What is the time complexity of finding the maximum element in a sorted array?
O(n log n)
O(log n)
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)
Which of the following is a valid array declaration in a common programming language (syntax may vary slightly)?
int numbers[] = {1, 2, 3, 4};
array numbers = [1, 2, 3, 4];
All of the above.
numbers = array(1, 2, 3, 4);
You want to find the first occurrence of a specific element in a sorted array. Which search algorithm is the most efficient?
It depends on the size of the array.
Linear Search
Binary Search
Both are equally efficient in this case.
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?
Create a new 2D array with the swapped rows.
Swapping rows is not possible in a 2D 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.