What is the time complexity of finding the maximum element in a sorted array?
O(n)
O(1)
O(n log n)
O(log n)
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.
Given an array of integers, how can you efficiently count the occurrences of a specific element?
All of the above methods are equally efficient.
Use a hash map to store the frequency of each element.
Iterate through the array and increment a counter for each occurrence.
Sort the array and use binary search.
Accessing an element outside the valid index range of an array leads to what kind of error?
IndexError or OutOfBounds exception
TypeError
ValueError
SyntaxError
You want to find the first occurrence of a specific element in a sorted array. Which search algorithm is the most efficient?
Linear Search
It depends on the size of the array.
Both are equally efficient in this case.
Binary Search
In an array with indices starting at 0, what is the index of the last element in an array of size 'n'?
n
It depends on the data type of the array.
n - 1
0
What is the purpose of having a base address associated with an array in memory?
To store the length of the array.
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.
Which operation is typically NOT efficient on a standard array?
Finding the length of the array.
Updating an element at a given index.
Retrieving the value at a given index.
Inserting an element at the beginning.
What is the space complexity of storing a 2D array with 'm' rows and 'n' columns?
O(m * n)
O(m)
What is the primary advantage of using binary search over linear search?
Binary search is simpler to implement.
Binary search uses less memory.
Binary search is generally faster for large arrays.
Binary search works on unsorted arrays.