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 |
Display names and numbers of employees who have 5 years or more experience and salary less than Rs.15000 using array of structures (name, number, experience and salary)
When should the register modifier be used? Does it really help?
Explain what is the difference between the expression '++a' and 'a++'?
What are the ways to a null pointer can use in c programming language?
What are types of functions?
What is the difference b/w Structure & Union?
printf("%d",(printf("Hello")); What it returns?
What are the advantages and disadvantages of a heap?
The number of bytes of storage occupied by short, int and long are a) 2, 2 and 4 b) 2, 4 and 4 c) 4, 4 and 4 d) none
How can my program discover the complete pathname to the executable from which it was invoked?
program for following output using for loop? 1 2 3 4 5 2 3 4 5 3 4 5 4 5 5
define string ?