Question
What is the best-case time complexity of the binary
search algorithm ?Solution
The best-case time complexity of the binary search algorithm is O(1), which occurs when the target element is found at the middle index on the very first comparison. Binary search divides the array into two halves and compares the middle element with the target. If the middle element matches the target, the search terminates immediately, requiring only one comparison. This efficiency makes binary search a powerful tool for sorted data. Why Other Options Are Incorrect :
- O(n) : This is the time complexity of linear search, where each element is compared sequentially. Binary search is much faster than linear search for sorted data.
- O(log ā” n) : This is the average and worst-case time complexity of binary search, not the best case.
- O(n2) : This is the complexity of algorithms like bubble sort or selection sort, not binary search.
- O(nlog ā” n) : This is the complexity of efficient sorting algorithms like merge sort, not binary search.
A person invests a sum of money in two schemes, P and Q. Scheme P offers simple interest, and Scheme Q offers compound interest. The amount invested in ...
In each of the following questions, a question is followed by information given in three statements. You have to study the question along with the stat...
What is the capacity of a cylindrical tank?
I. The radius of the base is half of its height, which is 42 meters.
II. The area of the base ...
What is the profit%/loss% incurred by selling an article for Rs. 44,000?
Statement I: The difference between the cost price and the selling pric...
What is the value of number x ?
I. The HCF of x and 16 is 8.
II. The LCM of ...
There are 7 people in a group. Average age of the group decreases by 5 when two more people join the group. Find the average age of the new group.
<...Determine the time taken by a pipe R to empty a water tank.
Statement I: Pipe P and pipe Q can fill a water tank in 6 hou...
How much profit did the company earn in the year 2016?
I) The company earned 45% more profit in the year 2017 than that in the year 2015.
...
A box contains red and blue marbles. What is the ratio of red marbles to blue marbles in the box?
Statements I: Ā The number of red marbles is 4...
How many students in a class can write both French and Spanish?
I. In the class, 25% of the total students can write Spanish and two-fifth of the...