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?
Bubble Sort
Depth First Search (DFS)
Quick Sort
Binary Search
Which sorting algorithm works by repeatedly selecting the minimum element and placing it in its correct position?
Merge Sort
Selection Sort
What is the primary advantage of using binary search over linear search?
Binary search is simpler to implement.
Binary search works on unsorted arrays.
Binary search uses less memory.
Binary search is generally faster for large arrays.
You need to search for an element in an array where elements are randomly placed. Which search algorithm is your only option?
None of the above.
Both can be used effectively.
Linear Search
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?
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.
Create a new 2D array with the swapped rows.
Swapping rows is not possible in a 2D array.
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.
0
n
n - 1
What is a key difference between a 1D array and a 2D array?
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.
1D arrays store numbers while 2D arrays store characters.
What is the space complexity of storing a 2D array with 'm' rows and 'n' columns?
O(m * n)
O(n)
O(1)
O(m)
What is the time complexity of accessing an element in a 2D array with 'm' rows and 'n' columns?
O(m + n)
O(log m + log n)
Accessing an element outside the valid index range of an array leads to what kind of error?
ValueError
TypeError
SyntaxError
IndexError or OutOfBounds exception