In which case(s) does Binary Search perform in O(1) time complexity?
- When the array is empty
- When the target element is at the first index of the array
- When the target element is at the middle of the array
- When the target element is not present in the array
Binary Search performs in O(1) time complexity when the target element is at the first index of the sorted array. In this case, it can directly access the element and return it. When the array is empty, it still performs in O(1) time complexity as there are no elements to search. In other cases, it performs in O(log n) time complexity, where 'n' is the number of elements in the array.
Loading...
Related Quiz
- In which scenario would you choose an abstract class over an interface?
- Envisage a situation where you are developing a high-throughput application where multiple threads are reading and writing to a data structure. Which collection would you select to store data and why?
- What is the impact of declaring a constructor private in a class?
- Externalizable interface extends ______ interface and adds two methods into it.
- To obtain a string representation of a primitive data type, you can use the static valueOf method of the ________ class.