Consider an array A = {1, 2, 4, 5, 6, 11, 12} and a key which is equal to 10. How many comparisons would be done to find the key element in the array using the binary search? A. 5 B. 1 C. 2 D. 3 explanation please
Share
Consider an array A = {1, 2, 4, 5, 6, 11, 12} and a key which is equal to 10. How many comparisons would be done to find the key element in the array using the binary search? A. 5 B. 1 C. 2 D. 3 explanation please
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer: 3
Explanation:
T(n)=T(n/2)+1 to solve the problem
n/2^k=1
taking log on both sides
log n=log (2^k)
log n= k log 2
k=log n base 2.
N=7
K=log 7 base 2 = 3
K=3
D. 3 comparisons are needed to find the key element in the array using the binary search.
Explanation:
Hence total of 3 comparisons was done while searching the key using binary search.