1. Home
  2. Computing & Technology
  3. C / C++ / C#

Definition of Binary Chop

By David Bolton, About.com

Definition: A binary chop is an algorithm for searching a sorted array for a value. This takes Log2 comparisons (or less) to find the value which compares very favourably with a brute force approach. This works by guessing the number halfway between the upper and lower limits, call them U and L. The guess G = (U+L)/2. If the guess G is too high then the new U = G and the next guess is the (U + L)/2. If the guess is too low then U = L. and so on, successively dividing the search range until the value is guessed (or U=L).

You can demonstrate this by playing a guessing game. If I pick a number between 1 and 1024, you should be able to guess it in a maximum of ten guesses as 210 = 1024. Say I guess 800. You guess 500 which I tell you is too low. Your next guess should be halfway between your upper limit and your low limit which is now 500. So now you guess (1024+500)/2 = 762. That is still too low so you guess (1024+ 762)/2 = 881. That's too high so your next guess is (881 + 762)/2 = 821. That is still too high so you guess (821 + 762)/2 which is 791. Next guess is (821 + 791)/2 = 806, then (806 + 791)/2 = 798 then (806 + 798)/2 = 802 then (802 + 798) = 800! It took nine guesses.

Glossary:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Explore C / C++ / C#
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

©2009 About.com, a part of The New York Times Company.

All rights reserved.