What is the time complexity of accessing an element in a 2D array with 'm' rows and 'n' columns?
O(m + n)
O(1)
O(log m + log n)
O(m * n)
Which of the following is a valid array declaration in a common programming language (syntax may vary slightly)?
array numbers = [1, 2, 3, 4];
All of the above.
int numbers[] = {1, 2, 3, 4};
numbers = array(1, 2, 3, 4);
Which code snippet correctly initializes a 2D array named 'grid' with 3 rows and 4 columns, all filled with zeros?
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}};
int grid[3][4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int grid[3][4] = {0};
What is the main disadvantage of using bubble sort for large datasets?
It is difficult to implement.
It cannot handle duplicate values.
It has a high time complexity, making it inefficient.
It requires additional memory space.
How can you efficiently delete a specific element from the middle of a sorted array while maintaining the sorted order?
By directly removing the element and leaving the space empty.
Deletion in a sorted array always disrupts the order.
By swapping the element with the last element and then removing it.
By shifting all the elements after the deleted element one position back.
In an array with indices starting at 0, what is the index of the last element in an array of size 'n'?
It depends on the data type of the array.
n
n - 1
0
Which sorting algorithm works by repeatedly selecting the minimum element and placing it in its correct position?
Selection Sort
Bubble Sort
Merge Sort
Quick Sort
What is the space complexity of storing a 2D array with 'm' rows and 'n' columns?
O(n)
O(m)
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.get(i, j)
matrix[i, j]
Given an array of integers, how can you efficiently count the occurrences of a specific 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.
Use a hash map to store the frequency of each element.