You want to find the first occurrence of a specific element in a sorted array. Which search algorithm is the most efficient?
Binary Search
Both are equally efficient in this case.
It depends on the size of the array.
Linear Search
What is the time complexity of finding the length of an array in most programming languages?
O(1) - Constant Time
O(n) - Linear Time
O(n^2) - Quadratic Time
O(log n) - Logarithmic Time
Which of the following sorting algorithms has the best average-case time complexity?
Selection Sort
Insertion Sort
Bubble Sort
Merge Sort
What is the time complexity of finding the maximum element in a sorted array?
O(n log n)
O(log n)
O(n)
O(1)
Given an array of integers, how can you efficiently count the occurrences of a specific element?
Iterate through the array and increment a counter for each occurrence.
Sort the array and use binary search.
All of the above methods are equally efficient.
Use a hash map to store the frequency of each element.
What is the primary advantage of using binary search over linear search?
Binary search works on unsorted arrays.
Binary search uses less memory.
Binary search is simpler to implement.
Binary search is generally faster for large arrays.
How is an element at row 'i' and column 'j' typically accessed in a 2D array named 'matrix'?
matrix[i][j]
matrix.get(i, j)
matrix(i)[j]
matrix[i, j]
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 directly removing the element and leaving the space empty.
Deletion in a sorted array always disrupts the order.
By swapping the element with the last element and then removing it.
What is the space complexity of storing a 2D array with 'm' rows and 'n' columns?
O(m)
O(m * 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 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.
The new element will overwrite the value at the first index (index 0).