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



write an algorithm which can find the largest number among the given list using binary search .......

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

write an algorithm which can find the largest number among the given list using binary search .......

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

Post New Answer

More C Interview Questions

what is the use of #pragma pack, wer it is used?

2 Answers   Wipro,


write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.

0 Answers   Subex,


Why doesnt the call scanf work?

0 Answers  


What is #ifdef ? What is its application?

0 Answers   TCS,


How are portions of a program disabled in demo versions?

0 Answers  






which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;

0 Answers  


Explain how can I remove the trailing spaces from a string?

0 Answers  


what is the difference between NULL('\0') and 0?

14 Answers   Microsoft,


What does typeof return in c?

0 Answers  


Explain can static variables be declared in a header file?

0 Answers  


Whether there can be main inside another main?If so how does it work?

14 Answers   Sail, Wipro,


Which is an example of a structural homology?

0 Answers  


Categories