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, 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};
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 identify the starting memory location where the array is stored.
To indicate the data type of elements stored in the array.
To store the length of the array.
How can you efficiently delete a specific element from the middle of a sorted array while maintaining the sorted order?
By swapping the element with the last element and then removing it.
Deletion in a sorted array always disrupts the order.
By shifting all the elements after the deleted element one position back.
By directly removing the element and leaving the space empty.
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 requires additional memory space.
It cannot handle duplicate values.
What is the time complexity of finding the length of an array in most programming languages?
O(n^2) - Quadratic Time
O(1) - Constant Time
O(n) - Linear Time
O(log n) - Logarithmic Time
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?
Directly assign 'image[r1]' to 'image[r2]' and vice-versa.
Create a new 2D array with the swapped rows.
Iterate through columns, swapping elements at 'image[r1][j]' and 'image[r2][j]' for each column 'j'.
Swapping rows is not possible in a 2D array.
Which operation is typically NOT efficient on a standard array?
Finding the length of the array.
Retrieving the value at a given index.
Inserting an element at the beginning.
Updating an element at a given index.
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.
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)
Bubble Sort
Quick Sort
Which of the following is a valid array declaration in a common programming language (syntax may vary slightly)?
int numbers[] = {1, 2, 3, 4};
All of the above.
array numbers = [1, 2, 3, 4];
numbers = array(1, 2, 3, 4);