Which of the following is a valid array declaration in a common programming language (syntax may vary slightly)?
numbers = array(1, 2, 3, 4);
int numbers[] = {1, 2, 3, 4};
All of the above.
array numbers = [1, 2, 3, 4];
If you have an array of size 5 and you try to add a 6th element to it, what is a likely outcome?
The new element will overwrite the value at the first index (index 0).
The array will automatically resize to accommodate the new element.
An error or exception will occur indicating an out-of-bounds access.
The behavior is undefined and can lead to unpredictable program crashes.
Which sorting algorithm works by repeatedly selecting the minimum element and placing it in its correct position?
Bubble Sort
Quick Sort
Merge Sort
Selection Sort
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(log n) - Logarithmic Time
O(n) - Linear 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?
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.
Swapping rows is not possible in a 2D array.
Create a new 2D array with the swapped rows.
Which operation is typically NOT efficient on a standard array?
Retrieving the value at a given index.
Finding the length of the array.
Inserting an element at the beginning.
Updating an element at a given index.
What is the purpose of having a base address associated with an array in memory?
To indicate the data type of elements stored in the array.
To identify the starting memory location where the array is stored.
To store the value of the first element in the array.
To store the length of the array.
You want to find the first occurrence of a specific element in a sorted array. Which search algorithm is the most efficient?
Linear Search
Binary Search
Both are equally efficient in this case.
It depends on the size of the array.
Which code snippet correctly initializes a 2D array named 'grid' with 3 rows and 4 columns, all filled with zeros?
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};
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};
How can you efficiently delete a specific element from the middle of a sorted array while maintaining the sorted order?
By directly removing the element and leaving the space empty.
By shifting all the elements after the deleted element one position back.
By swapping the element with the last element and then removing it.
Deletion in a sorted array always disrupts the order.