What is the time complexity of finding the maximum element in a sorted array?
O(1)
O(n)
O(n log n)
O(log n)
You are given a 2D array representing a matrix. What does transposing this matrix mean?
Sorting the matrix in ascending order.
Reversing all elements in the matrix.
Finding the sum of all elements in the matrix.
Swapping rows and columns of the matrix.
Given an array of integers, how can you efficiently count the occurrences of a specific element?
Use a hash map to store the frequency of each element.
Iterate through the array and increment a counter for each occurrence.
Sort the array and use binary search.
All of the above methods are equally efficient.
You need to search for an element in an array where elements are randomly placed. Which search algorithm is your only option?
Binary Search
Both can be used effectively.
Linear Search
None of the above.
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] = {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;
In an array with indices starting at 0, what is the index of the last element in an array of size 'n'?
n - 1
n
0
It depends on the data type of the array.
Which of the following sorting algorithms has the best average-case time complexity?
Selection Sort
Merge Sort
Bubble Sort
Insertion Sort
What is the space complexity of storing a 2D array with 'm' rows and 'n' columns?
O(m * n)
O(m)
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.
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.
Directly assign 'image[r1]' to 'image[r2]' and vice-versa.
Iterate through columns, swapping elements at 'image[r1][j]' and 'image[r2][j]' for each column 'j'.