Top Topics
-
San Antonio Spurs vs. Oklahoma City Thunder
1319 recent check-ins -
Sleep
467 recent check-ins -
NBA Playoffs
390 recent check-ins -
Coffee
248 recent check-ins -
GetGlue
196 recent check-ins
-
Your Review
Loading - Loading
1 people checked-in to Binary search algorithm on GetGlue
Check-in to entertainment with GetGlue. Connect with friends, discover new favorites, and unlock FREE stickers and discounts.
In computer science, a binary search algorithm (or binary chop) is a technique for locating a particular value in a sorted list. The method makes progressively better guesses, and closes in on the location of the sought value by selecting the middle element in the span (which, because the list is in sorted order, is the median value), comparing its value to the target value, and determining if it is greater than, less than, or equal to the target value. A guessed index whose value turns out to be too high becomes the new upper bound of the span, and if its value is too low that index becomes the new lower bound.
Only the sign of the difference is inspected: there is no attempt at an interpolation search based on the size of the difference. Pursuing this strategy iteratively, the method reduces the search span by a factor of two each time, and soon finds the target value or else determines that it is not in the list at all. A binary search is an example of a dichotomic divide and conquer search algorithm.
Finding the index of a specific value in a sorted list is useful because, given the index, other data structures will contain associated information. Suppose a data structure containing the classic collection of name, address, telephone number and so forth has been accumulated, and an array is prepared containing the names, numbered from one to N. A query might be: what is the telephone number for a given name X.
To answer this the array would be searched and the index (if any) corresponding to that name determined, whereupon the associated telephone number array would have X's telephone number at that index, and likewise the address array and so forth. Appropriate provision must be made for the name not being in the list (typically by returning an index value of zero), indeed the question of interest might be only whether X is in the list or not. If the list of names is in sorted order, a binary search will find a given name with far fewer probes than the simple procedure of probing each name in the list, one after the other in a linear search, and the procedure is much simpler than organizing a hash table.
However, once created, searching with a hash table may well be faster, typically averaging just over one probe per lookup. With a non-uniform distribution of values, if it is known that some few items are much more likely to be sought for than the majority, then a linear search with the list ordered so that the most popular items are first may do better than binary search. The choice of the best method may not be immediately obvious.
If, between searches, items in the list are modified or items are added or removed, maintaining the required organisation may consume more time than the searches.
Similar to 0 things you like:
San Antonio Spurs vs. Oklahoma City Thunder
Sleep
NBA Playoffs
Coffee
GetGlue
Check-in to entertainment with GetGlue. Connect with friends, discover new favorites, and unlock FREE stickers and discounts.
You can edit this page because you have earned special privileges on Glue.
Only make changes if you are certain that they are correct.
Made in New York City | Copyright 2009-2012, AdaptiveBlue, Inc