COMPUTER SCIENCE AND ENGINEERING
ALGORITHMS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
1
|
|
3
|
|
6
|
|
7
|
Detailed explanation-1: -Thus, the number of iterations needed to find the item is 3 iterations.
Detailed explanation-2: -The maximum number of iterations or invocations would thus be 10 for a data set of 1024 items, for example, because the logarithm to the base of two of 1024 is 10. The worst case scenario for a linear search would be 1024 for the same data set.
Detailed explanation-3: -Mathematically Maximum iteration possible (Assuming case of only integer type) is = ceil( log2 ( initial r-initial l ) ) base of log is 2 because every time we are diving our range in half by taking a mid and switching to one of the half.
Detailed explanation-4: -The number of comparisons necessary to get to this point is i where n2i=1. Solving for i gives us i=logn. The maximum number of comparisons is logarithmic with respect to the number of items in the list. Therefore, the binary search is O(logn).
Detailed explanation-5: -It examines up to log2(n) elements.