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

How can I find the modification date and time of a file?

0 Answers  


How to find the given no is odd or even without checking of any condition and loops. (Hint: Using array)

4 Answers  


how to find out the union of two character arrays?

2 Answers  


How are variables declared in c?

0 Answers  


WHAT IS HEADER?

8 Answers   ProKarma, TCS,






write a program to print sum of each row of a 2D array.

4 Answers  


What is the meaning of ?

0 Answers  


What is main () in c?

0 Answers  


prototype of sine function.

2 Answers   Cadence,


Can you mix old-style and new-style function syntax?

0 Answers  


write a program to sort the elements in a given array in c language

10 Answers   TCS,


WHAT IS LOW LEVEL LANGUAGE?

2 Answers  


Categories