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 is simpler to implement.
Binary search uses less memory.
If you have an array of size 5 and you try to add a 6th element to it, what is a likely outcome?
The array will automatically resize to accommodate the new element.
The behavior is undefined and can lead to unpredictable program crashes.
An error or exception will occur indicating an out-of-bounds access.
The new element will overwrite the value at the first index (index 0).
In an array with indices starting at 0, what is the index of the last element in an array of size 'n'?
n
0
It depends on the data type of the array.
n - 1
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.
Sort the array and use binary search.
Iterate through the array and increment a counter for each occurrence.
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, 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};
Which of the following sorting algorithms has the best average-case time complexity?
Merge Sort
Selection Sort
Bubble Sort
Insertion Sort
What is the time complexity of finding the maximum element in a sorted array?
O(n log n)
O(1)
O(n)
O(log n)
You are given a 2D array representing a matrix. What does transposing this matrix mean?
Sorting the matrix in ascending order.
Reversing all elements in the matrix.
Swapping rows and columns of the matrix.
Finding the sum of all elements in the matrix.
Which sorting algorithm works by repeatedly selecting the minimum element and placing it in its correct position?
Quick Sort
Accessing an element outside the valid index range of an array leads to what kind of error?
TypeError
IndexError or OutOfBounds exception
ValueError
SyntaxError