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

write a c program to store and print name,address,roll.no of a student using structures?

7 Answers  


Why static variable is used in c?

0 Answers  


Are the expressions * ptr ++ and ++ * ptr same?

0 Answers  


int a=1,b=2,c=3; printf("%d,%d",a,b,c); What is the output?

14 Answers   Verifone,


What's the difference between DELETE TABLE and TRUNCATE TABLE commands?

2 Answers   CTC,


Explain how can you avoid including a header more than once?

0 Answers  


What is #include stdio h and #include conio h?

0 Answers  


int main() { int i=1; switch(i) { case '1': printf("hello"); break; case 1: printf("Hi"); break; case 49: printf("Good Morning"); break; } return 0; }

3 Answers  


what are the 10 different models of writing an addition program in C language?

0 Answers  


What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25

0 Answers  


union { char ch[10]; short s; }test; test.s = 0xabcd; main() { printf("%d",ch[10]); }

3 Answers  


what is mean by Garbage collection ? Please answer me. Advance thanks.

4 Answers   Excel,


Categories