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.
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]; 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}};
Which of the following sorting algorithms has the best average-case time complexity?
Selection Sort
Merge Sort
Bubble Sort
Insertion Sort
In an array with indices starting at 0, what is the index of the last element in an array of size 'n'?
n - 1
0
n
It depends on the data type of the array.
What is the time complexity of finding the length of an array in most programming languages?
O(n^2) - Quadratic Time
O(n) - Linear Time
O(log n) - Logarithmic Time
O(1) - Constant Time
Accessing an element outside the valid index range of an array leads to what kind of error?
ValueError
IndexError or OutOfBounds exception
TypeError
SyntaxError
Given an array of integers, how can you efficiently count the occurrences of a specific element?
Use a hash map to store the frequency of each element.
All of the above methods are equally efficient.
Sort the array and use binary search.
Iterate through the array and increment a counter for each occurrence.
You want to find the first occurrence of a specific element in a sorted array. Which search algorithm is the most efficient?
Binary Search
It depends on the size of the array.
Both are equally efficient in this case.
Linear Search
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)
O(m * n)
O(1)
What is the space complexity of storing a 2D array with 'm' rows and 'n' columns?
O(n)
O(m)