MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
BMO the robot is programming a new game called “Open the box!” You give him a number and he tries to open a numbered box. He’s using Binary Search to accomplish this. Unfortunately, the boxes are not sorted. They are in the following order:1, 3, 6, 9, 14, 10, 21Which box can NEVER be found using binary search?
A
9
B
6
C
14
D
10
Explanation: 

Detailed explanation-1: -What must be true before performing a binary search? The elements must be sorted.

Detailed explanation-2: -The number of comparisons necessary to get to this point is i where n/2i =1. Solving for i gives us i =log n . The maximum number of comparisons is logarithmic with respect to the number of items in the list. Therefore, the binary search is O(log n) .

Detailed explanation-3: -Binary search is more efficient (faster) because it starts at the middle of a sorted array or ArrayList and eliminates half of the array or ArrayList each pass through the algorithm. Binary search only works on sorted data. It can be written with iteration (using a loop) like below or recursively.

Detailed explanation-4: -Answer: The statement is true. Binary search provide an efficient searching technique for finding an item from a sorted list of items. In this searching technique checks the presence of the searching element with the middle element of the given set of elements at each iteration.

There is 1 question to complete.