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.
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'.
Create a new 2D array with the swapped rows.
What is the purpose of having a base address associated with an array in memory?
To store the value of the first element in the array.
To indicate the data type of elements stored in the array.
To store the length of the array.
To identify the starting memory location where the array is stored.
Accessing an element outside the valid index range of an array leads to what kind of error?
ValueError
IndexError or OutOfBounds exception
TypeError
SyntaxError
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.
None of the above.
Linear Search
Which of the following sorting algorithms has the best average-case time complexity?
Bubble Sort
Insertion Sort
Merge Sort
Selection Sort
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?
Depth First Search (DFS)
Quick Sort
What is the space complexity of storing a 2D array with 'm' rows and 'n' columns?
O(m)
O(n)
O(m * n)
O(1)
What is a key difference between a 1D array and a 2D array?
1D arrays store numbers while 2D arrays store characters.
1D arrays can only be accessed sequentially, 2D arrays allow random access.
1D arrays represent linear sequences, 2D arrays represent tabular data.
1D arrays are static in size, 2D arrays can change size dynamically.
In an array with indices starting at 0, what is the index of the last element in an array of size 'n'?
n - 1
It depends on the data type of the array.
n
0
Which operation is typically NOT efficient on a standard array?
Inserting an element at the beginning.
Finding the length of the array.
Retrieving the value at a given index.
Updating an element at a given index.