In general, the binary search method needs no more than __________________ comparisons. A) [log2n]-1 B) [logn]+1 C) [log2n] D) [log2n]+1 Explain
Ans:[log2n]+1
The performance of binary search can be analyzed by viewing the run on a binary tree where root node is the middle element of the array. Left child node of the root is the middle element of the lower part and the right child node of the root is the middle element of the upper part.Starting from the root we traverse towards the left side or the right side depending on the key value(whether it is greater or less than the root node).
In the worst case binary search makes [log2n]+1 iterations because we know that the level of a tree is found by [log2n]+1.And worst case is reached when search reaches the last level of the tree.
we also know that the highest number of comparisons are done during the worst case only.Thus the answer would be [log2n]+1.
Get Answers For Free
Most questions answered within 1 hours.