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.
Iterate through the array and increment a counter for each occurrence.
All of the above methods are equally efficient.
Sort the array and use binary search.
How can you efficiently delete a specific element from the middle of a sorted array while maintaining the sorted order?
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.
By directly removing the element and leaving the space empty.
What is the time complexity of finding the maximum element in a sorted array?
O(n)
O(log n)
O(n log n)
O(1)
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)
In an array with indices starting at 0, what is the index of the last element in an array of size 'n'?
n - 1
n
It depends on the data type of the array.
0
Which operation is typically NOT efficient on a standard array?
Inserting an element at the beginning.
Retrieving the value at a given index.
Updating an element at a given index.
Finding the length of the array.
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 behavior is undefined and can lead to unpredictable program crashes.
An error or exception will occur indicating an out-of-bounds access.
The array will automatically resize to accommodate the new element.
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 length of the array.
To store the value of the first element in the array.
What is a key difference between a 1D array and a 2D array?
1D arrays can only be accessed sequentially, 2D arrays allow random access.
1D arrays store numbers while 2D arrays store characters.
1D arrays represent linear sequences, 2D arrays represent tabular data.
1D arrays are static in size, 2D arrays can change size dynamically.
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?
Depth First Search (DFS)
Quick Sort
Binary Search
Bubble Sort