Home Answers Viewqa Java-Beginners Send me Binary Search

 
 


joginder singh
Send me Binary Search
1 Answer(s)      4 years and 8 months ago
Posted in : Java Beginners

View Answers

November 11, 2008 at 4:02 AM


Hi friend,

import java.io.*;

public class BinarySearchDemo {
public static final int NOT_FOUND = -1;

public static <AnyType extends Comparable<? super AnyType>>
int binarySearch(AnyType [] a, AnyType x ){
int low = 0;
int high = a.length - 1;
int mid;

while(low <= high ){
mid = (low + high)/ 2;
if(a[mid].compareTo(x) < 0)
low = mid + 1;

else if(a[mid].compareTo(x) > 0 )
high = mid - 1;
else
return mid;
}
return NOT_FOUND;
}

public static void main(String[]args) throws IOException{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter number!");
int SIZE = Integer.parseInt(buff.readLine());
Integer []a = new Integer[SIZE];
for(int i = 0; i < SIZE; i++)
a[i] = i * 2;

for(int i = 0; i < SIZE * 2; i++)
System.out.println("Found " + i + " at " + binarySearch(a, i));

}
}

-----------------------------------------

Read for more information.

http://www.roseindia.net/java/

Thanks.









Related Pages:
Send me Binary Search - Java Beginners
Send me Binary Search  how to use Binary think in java give me the Binary Search programm thx..  Hi friend, import java.io.*; public class BinarySearchDemo { public static final int NOT_FOUND = -1
Binary Search - Java Beginners
Binary Search  how to use Binary think in java give me the Binary Search programm thx
JAVA: Recusrion, Binary Search
JAVA: Recusrion, Binary Search  I want to learn about Binary Search... it using a recursive implementation of Binary Search. For the cases when more than one result can be returned, modify Binary Search to return all the elements
binary search tree
binary search tree  how can i make binary search tree? i want write a code that make dictionary with binary search tree data structure.please help me...){ IsEmpty(); currentNode = find(root, number); System.out.println("Search
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
How to create binary search tree using an array?
How to create binary search tree using an array?  hello people, pls guide me on the topic above. i have an string array, i want to make a binary search tree based on data inside this array. the array contains names of people
Binary Search on array
Binary Search on array  What requirement is placed on an array, so that binary search may be used to locate an entry? â?º The array elements must form a heap. â?º The array must have at least 2 entries. â?º The array must
send Binary Data by doGet or doPost?
send Binary Data by doGet or doPost?  which method in doGet or doPost is use to send binary date to server
binary search tree
binary search tree  Construct a binary search tree by inserting the following sequence of characters into an empty tree. N O N L I N E A R D A T... for each algorithm. get an item from the user and search the level/levels
binary search tree
binary search tree  Construct a binary search tree by inserting words into an empty tree. "cut your coat according to your cloth" Visit the tree.... get a word from the user and search the level/levels of that word. refer split
Binary Search Tree
Binary Search Tree  Question-1 ) Modify the BinarySearchTree class so that the iterators are fail-fast.Test your class with amain method ? Question-2 ) Modify the BinarySearchTree class so that the BinarySearchTree objects
Binary Search Tree
Binary Search Tree  Question-1 ) Modify the BinarySearchTree class so that the iterators are fail-fast.Test your class with amain method ? Question-2 ) Modify the BinarySearchTree class so that the BinarySearchTree objects
binary search - Java Beginners
binary search  Write a java program to search an array by using recursive binary search.  /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package
Binary Search!!! - Java Beginners
Binary Search!!!  Hi Sir, My question is quite simple. im only... = Integer.parseInt(searchKeyText); position = search(searchKey, arrayList, 0... to continue?"); } } public static int search(int target, int
Algorithms: Binary Search
Java Notes: Algorithms: Binary Search Divide in half A fast way to search a sorted array is to use a binary search. The idea is to look at the element... is less than the middle element, do a binary search on the first half
JavaScript Array Binary Search
JavaScript Array Binary Search       The JavaScript Binary Search becomes very useful in case of large Arrays.  The Binary Search algorithm is used to  handle
Binary search tree (insertion) urgent!!
Binary search tree (insertion) urgent!!  Create a program to construct a binary search tree consisting of nodes that each stores an integer.... Assume a binary search tree is constructed from the values 14, 35, 2, 3, 39
Binary Search in Java
Binary Search in Java In this section, we are going to search an element from an array using Binary Search. The advantage of a binary search over a linear search is astounding for large numbers. It can be done either recursively
Which of the following statements are true with respect to binary search
Which of the following statements are true with respect to binary search  Which of the following statements are true with respect to binary search? 1. The array need not be sorted for carrying out binary search 2. Binary search
How to using Binary Search Array Java ?
How to using Binary Search Array Java ?  Hi, I am beginners in Java... functions. The problem is that how to use binary search array in Java. Please give any online reference show that i will implement the binary search array in Java
hex to binary convertion in java - Java Beginners
hex to binary convertion in java  HI, im doin a application wch requires to send a binary message to other mobiles, so i need to convert the hex values to binary format.So the binary format could either be a ringtone
hex to binary convertion in java - Java Beginners
hex to binary convertion in java  HI, im doin a application wch requires to send a binary message to other mobiles, so i need to convert the hex values to binary format.So the binary format could either be a ringtone
hex to binary convertion in java - Java Beginners
hex to binary convertion in java  HI, im doin a application wch requires to send a binary message to other mobiles, so i need to convert the hex values to binary format.So the binary format could either be a ringtone
php array binary search
PHP Binary Search Array is used to search the given value in the array. In php there is no function for the binary search like java or other language. User can implement and use the binary search in php as given below
Java Array Binary Search example
Java Array Binary Search It is a method for searching the array element... the binary search algorithm.  It returns the index of the found element... example demonstrates how to do a binary search on the Java array object
binary search tree from text file
binary search tree from text file  How so I go about constructing a binary search tree from a text file, which has letters and numbers, which must be sorted and printed in ascending order. E.g. Text file contents 3 apples pears
send me example of jmsmq - JMS
send me example of jmsmq  please send me example about jmsmq (java microsoft message queuing ) library
Binary Search in Java
Binary Search in Java is used to search an element from an array. Programmers opt for Binary search over linear search when it comes to large numbers. It can... the answer "Not Found". Following is the example of Binary Search in Java: import
please send me the answer - JDBC
please send me the answer -difference between DriverManager and DataDourse   what is Datasourse? What r the advantages? what is the difference between DriverManager and DataDourse
Plz send me answer quckly
Plz send me answer quckly  Respected Sir, myself is pavan shrivastava.i want ask a question that is ( we can't create object of interface then how would possible to create object
binary addition,subtraction and modulus operations - Java Beginners
adder binary logic in this!!! please send me the java coding for these three...binary addition,subtraction and modulus operations  i wanna perform binary addition,subtraction and modulus operation between two numbers of 512 bit
error please send me the solution
error please send me the solution  HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception
error please send me the solution
error please send me the solution  HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception
jtable displays search results
jtable displays search results   hi sir can u send me full source code for displaying search results into jtable from database n jtable n search... must not be default. plz sir help me i have a urgent need
Search Engine - Java Beginners
Search Engine  Hello Sir, I am new jsp, also i need search engine coding from the local computer or database only.pls send the jsp with mysql codes.I dont know how to create a search engine(like google) in local computer
please send me the banking data base in swings
please send me the banking data base in swings  sir, please send me how to create the banking data base program in swings
how to search - WebSevices
problem then send me code and explain in detail, what's your proper query. import...how to search  how can I write mysql query for the following search format? Search By:(this have following options)(name,username,email
please help me.
please help me.  Please send me the validation of this below link. the link is http://www.roseindia.net/answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search-and-Edit.html Thanks Trinath
BINARY TO DECIMAL - Java Beginners
BINARY TO DECIMAL  HELP ME PLSS. PROGRAM THAT CONVERTS BINARY TO DECIMAL  Hi friend, Program to convert Binary To Decimal : import... (System.in); System.out.print ("Enter a binary number "); String str
send me javascript code - Java Beginners
send me javascript code  please send me code javascript validation code for this html page.pleaseeeeeeeee. a.first:link { color: green;text-decoration:none; } a.first:visited{color:green;text
Major Search Engines List
Major Search Engine Lists       Listing of 10 Top Search Engines Web sites receives most of the traffic from major search engines. You
binary
binary  Hi I want to write a program in pascal that ask a user to input a decimal number and then return its binary equivalent in the minimum number of bits required to repesent the number. Thks
Servlet Response Send Redirect - JSP-Servlet
: Please tell me whether index.jsp is the search page where we are displaying...Servlet Response Send Redirect  Hi, Thank you for your previous... to be able to do search on the Mysql table based on more than one column instead of one
Algorithms: Recursive Binary Search
Java Notes: Algorithms: Recursive Binary Search Recursive Binary Search... (eg, binary tree traversal). Iterative binary search is more efficient than... 20 21 22 23 24 25 26 27 28 /** Recursive binary search
SEARCH PAGE
SEARCH PAGE  search page:option for search criteria like name and DOB will be asked.on entering the detail,data matching search criteria will be displayed..criteria can be both or any one of them.. can you send code
Reply me - Java Beginners
in the database... if u understood my question then then please send me code oterwise tell me its urgent package services; import java.sql.Connection; import... Test1 { public void search() { String vend_name=""; String