Which of the following is a valid array declaration in a common programming language (syntax may vary slightly)?
All of the above.
numbers = array(1, 2, 3, 4);
array numbers = [1, 2, 3, 4];
int numbers[] = {1, 2, 3, 4};
Which sorting algorithm works by repeatedly selecting the minimum element and placing it in its correct position?
Quick Sort
Selection Sort
Bubble Sort
Merge Sort
What is the main disadvantage of using bubble sort for large datasets?
It cannot handle duplicate values.
It has a high time complexity, making it inefficient.
It is difficult to implement.
It requires additional memory space.
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
Which operation is typically NOT efficient on a standard array?
Inserting an element at the beginning.
Updating an element at a given index.
Retrieving the value at a given index.
Finding the length of the array.
Given an array of integers, how can you efficiently count the occurrences of a specific element?
Sort the array and use binary search.
Iterate through the array and increment a counter for each occurrence.
Use a hash map to store the frequency of each element.
All of the above methods are equally efficient.
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] = {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;
What is the primary advantage of using binary search over linear search?
Binary search is generally faster for large arrays.
Binary search uses less memory.
Binary search works on unsorted arrays.
Binary search is simpler to implement.
What is the time complexity of accessing an element in a 2D array with 'm' rows and 'n' columns?
O(m + n)
O(m * n)
O(log m + log n)
O(1)
Which of the following sorting algorithms has the best average-case time complexity?
Insertion Sort