Answer Posted / jamshed
SHORTEST BINARY SEARCH PROGRAM
import java.io.*;
class Binary
{
public static void main()throws IOException
{
InputStreamReader isr=new
InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
int a[]={5,7,9,11,15,20,30,45,89,97};
int n,c=0,l=0,u=9,m;
System.out.println("Enter a Number to Search");
n=Integer.parseInt(br.readLine());
while(u>l)
{
m=(l+u)/2;
if(a[m]==n)
{
c++;
break;
}
else if(a[m]>n)
u=m;
else if(a[m]<n)
l=m+1;
}
if(c==0)
System.out.println("Not Found");
else
System.out.println("Found");
}
}
| Is This Answer Correct ? | 14 Yes | 4 No |
Post New Answer View All Answers
What are sorting algorithms used for?
What is merge sort in daa?
What is array and string?
Explain binary searching, Fibonacci search.
What is data type in data structure?
Which sorting is best for large data?
What is a data structure node class?
Will this code give error if I try to add two heterogeneous elements in the arraylist? And why?
Who created quicksort?
Explain what is the bucket size, when the overlapping and collision occur at same time?
What are the disadvantages of sequential storage?
where do you use double linked list?
What is stack and its operations?
Is selection sort greedy?
How do you sort a collection in descending order?