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]; 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 time complexity of accessing an element in a 2D array with 'm' rows and 'n' columns?
O(log m + log n)
O(1)
O(m + n)
O(m * n)
Which of the following sorting algorithms has the best average-case time complexity?
Bubble Sort
Selection Sort
Insertion Sort
Merge Sort
Given an array of integers, how can you efficiently count the occurrences of a specific element?
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.
Iterate through the array and increment a counter for each occurrence.
Accessing an element outside the valid index range of an array leads to what kind of error?
TypeError
ValueError
IndexError or OutOfBounds exception
SyntaxError
What is the primary advantage of using binary search over linear search?
Binary search works on unsorted arrays.
Binary search is generally faster for large arrays.
Binary search uses less memory.
Binary search is simpler to implement.
What is a key difference between a 1D array and a 2D array?
1D arrays represent linear sequences, 2D arrays represent tabular data.
1D arrays store numbers while 2D arrays store characters.
1D arrays can only be accessed sequentially, 2D arrays allow random access.
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'?
It depends on the data type of the array.
n
n - 1
0
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?
Binary Search
Depth First Search (DFS)
Quick Sort
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 store the length of the array.
To identify the starting memory location where the array is stored.
To indicate the data type of elements stored in the array.