Aditi
Company
Category
.Swathi writes a program to find an element in the array A[5] with the following elements in order : 8, 30, 40, 45, 70. She runs the program to find a number X. X is found in the first iteration of binary search. What is the value of X?
Read Solution (Total 1)
-
- 40 is the answer,
Because in the binary search first we will find the mid value i.e mid=(low+high)/2;
here low=A[0]=8 and high=A[4]=70; so mid value is A[mid]= 40(i.e( 0 +4)/2=2) so here we have 40 at index 2.
1st iteration in binary search is
if(A[mid]==A[i])
{
search is succesfull;
}
so answer is mid value i.e is 40 - 5 years agoHelpfull: Yes(1) No(0)
Aditi Other Question