Web Design, Development & Marketing
acuras services: Website Design & Development E-commerce Solutions Content Management Systems Online Marketing & Social Media Corporate Branding Social Media Training
Get in touch... Email Us: info@acuras.co.uk
acuras blog:7 Quick Tips to Keep Your SEO On Track in 2012 7 Social Media & SEO Tactics Businesses Will Adopt in 2012 latest posts:We are now trading as a Limited company Recent Work: Digital Marketing Material and Website Re-Designs Affordable Web Hosting and Domain Name Registration New Acuras Logo Coming Soon... Barclaycard ePDQ CPI Integrations HSBC XML API / CPI E-commerce Integrations Photoshop to Valid XHTML/CSS Coding Service Recommended Open Source Invoicing System Reasons Businesses should Embrace the Web blog archive:
Web Development ArticlesJava: Binary Search Algorithm Analysis and Code
Published: 29th Mar 2006
The Binary Search searches for an element in an ordered list. The algorithm initiates by visiting the middle of the list and comparing the middle value to the desired result or “target”. This target is typically specified by input from a user before the algorithm is executed. If the target is higher than the middle value, the bottom half of the list is discarded from the search. Alternatively, if the desired value is lower than the middle value, then the upper half of the list is discarded. This process is repeated until the desired search result is found. If the current middle value equals the search target, then the algorithm will terminate as it has accomplished its purpose and found the location of the target. The Binary Search is a much more effective search method than a sequential or linear search, for example, especially for large sets of data. An ideal application of the Binary Search would be searching for a record in an ordered list of employees which are kept in order by the employees’ unique ID. With this in mind, the Binary Search has the disadvantage of only being able to operate on an ordered set of data. Even so, there are many simple ways to order a list or set of data, and once sorted, the Binary Search can offer a very swift method of searching. The time complexity of the Binary Search is O(log(N)) which means it is a logarithmic algorithm. This means that as the input data increases in size, the algorithm gets more efficient. This efficiency is in terms of the relationship between its average execution time and the input data size. For large sets of data (this enables successful asymptotic analysis of the algorithm), if the input list size doubles (2N), the execution time will go from a factor of log(N) to log(2N) which is a lot less than double. A Java implementation of the Binary Search is shown below:
Check out the Computation and Algorithms section of the Computing Students website for information on some other search and sort algorithms. Another useful resource: Algorithms & Data Structures. Related LinksRelated Articles / PostsJava: Quick Sort Algorithm Analysis (13/06/2006) Java: Merge Sort Algorithm Analysis and Code (05/04/2006) Java: Random Array Generator (29/03/2006) Java: Insertion Sort Algorithm Analysis and Code (29/03/2006) Java: Binary Search Algorithm Analysis and Code (29/03/2006) |
||