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 is difference between arraylist and list?
What do you mean by probing?
What is data type and its types?
Which of the collections allows null as the key?
How is the front of the queue calculated in data structure?
What are the 3 types of measurement?
Is an arraylist an object?
What is a node in it?
What is priority queue in data structure?
State the advantages of using postfix notations?
How would you sort words in a large file?
Advanced problems related to Data Structures were asked
Why do we use stacks?
Define forest?
Which is faster quick sort or merge sort?