write an algorithm which can find the largest number among
the given list using binary search ...............
this was asked in the interview
Answers were Sorted based on User's Feedback
Answer / shruti
In binary search , we have sorted array.
Hence the last number in the array is the largest number
among the given list.. :-)
Ur interviewer has to be very intelligent.. :-)
Gud ques though..
| Is This Answer Correct ? | 18 Yes | 5 No |
Answer / vishnu948923
void main()
{
int a[10],i,flag,mid,low=0,high=9,num;
printf("enter how many elements");
scanf("%d",&num);
for(i=0;i<=9;i++)
scanf("%d",&a[i]);
for(mid=(low+high)/2; low<=high;mid=(low+high)/2)
{
if(a[mid]==num)
{
printf("Element position %d",mid);
flag=0;
break
}
if(a[mid]>num)
high=mid-1;
else
low=mid+1;
}
if(flag)
printf("element not present");
}
| Is This Answer Correct ? | 16 Yes | 14 No |
Which driver is a pure java driver
What happens if header file is included twice?
write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.
what is purpose of fflush(stdin) function
What is output of the following program ? main() { i = 1; printf("%d %d %d\n",i,i++,i++); }
wat s the meaning of (int *)p +4;
int *a[5] refers to
what do u mean by Direct access files? then can u explain about Direct Access Files?
what is the different between if-else and switch statment (other than syntax)
26 Answers CTS, Oracle, Scorpos,
void main() { int i=5; printf("%d",i++ + ++i); }
There is a 100-story building and you are given two eggs. The eggs (and the building) have an interesting property that if you throw the egg from a floor number less than X, it will not break. And it will always brake if the floor number is equal or greater than X. Assuming that you can reuse the eggs which didn't broke; you got to find X in a minimal number of throws. Give an algorithm to find X in minimal number of throws.
A array contains dissimilar element how can we count, and A array contains dissimilar element how can we store in another array with out repetition.