COMPUTER SCIENCE AND ENGINEERING
ALGORITHMS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
9
|
|
6
|
|
14
|
|
10
|
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.