MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Time complexity of binary search:
A
O(n)
B
O(log n)
C
O(1)
D
O(n2)
Explanation: 

Detailed explanation-1: -The time complexity of the binary search algorithm is O(log n). The best-case time complexity would be O(1) when the central index would directly match the desired value. Binary search worst case differs from that. The worst-case scenario could be the values at either extremity of the list or values not in the list.

Detailed explanation-2: -The beauty of balanced Binary Search Trees (BSTs) is that it takes O(log n) time to search the tree. Why is this? As the number of inputted elements increase, the number of operations stays the same for O(log n). With a balanced BST, we are always halving the number of elements that we look at.

Detailed explanation-3: -Binary search is an example with complexity O(log n) .

Detailed explanation-4: -Logarithmic time complexity log(n): Represented in Big O notation as O(log n), when an algorithm has O(log n) running time, it means that as the input size grows, the number of operations grows very slowly. Example: binary search.

Detailed explanation-5: -The main reason why binary search (which requires sorted data in a data structure with O(1) random access reads) is O(log N) is that for any given data set, we start by looking at the middle-most element.

There is 1 question to complete.