What is the space complexity of storing a 2D array with 'm' rows and 'n' columns?
O(m * n)
O(1)
O(n)
O(m)
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?
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'.
Create a new 2D array with the swapped rows.
Directly assign 'image[r1]' to 'image[r2]' and vice-versa.
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.
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, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
int grid[3][4] = {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};
What is the purpose of having a base address associated with an array in memory?
To indicate the data type of elements stored in the array.
To identify the starting memory location where the array is stored.
To store the value of the first element in the array.
To store the length of the array.
If you have an array of size 5 and you try to add a 6th element to it, what is a likely outcome?
The behavior is undefined and can lead to unpredictable program crashes.
The array will automatically resize to accommodate the new element.
An error or exception will occur indicating an out-of-bounds access.
The new element will overwrite the value at the first index (index 0).
In an array with indices starting at 0, what is the index of the last element in an array of size 'n'?
n
n - 1
It depends on the data type of the array.
0
What is the time complexity of finding the length of an array in most programming languages?
O(1) - Constant Time
O(n) - Linear Time
O(n^2) - Quadratic Time
O(log n) - Logarithmic Time
What is the main disadvantage of using bubble sort for large datasets?
It is difficult to implement.
It has a high time complexity, making it inefficient.
It cannot handle duplicate values.
It requires additional memory space.
Which of the following sorting algorithms has the best average-case time complexity?
Selection Sort
Bubble Sort
Merge Sort
Insertion Sort