Demonstration of a Binary Search in an Array

The applet below can be used to animate the Binary Search process through a randomly created list of values. When you click on the button labeled "run" a new window will pop-up with a diagram demonstrating one particular run of the binary search algorithm. To close the pop-up window, please click on the word "File" and then the word "close" near the top left corner of the pop-up window.

You can control the demonstration based on a number of parameters which you can modify. The first three parameters effect the way that the original array is created and the search key is chosen. The last three parameters effect the graphics. Here is a detailed explanation of each parameter:

  • #items - This value specifies the number of items to appear in the list which is searched.

  • target - This value specifies the particular number target value for which to search. (Notice that this target need not be present in the full list)

  • seed - In general, the demonstration picks a list of values at random. However, at times it is convenient to be able to re-run the demonstration using the same original list of numbers, but perhaps a different target. For this reason, the integer 'seed' will be used in a sense to control the selection of list values. If you change the seed, you will get a different list of values. If you re-run with the same seed, you will get the same list of values.

  • width - This is a measure of the width of the pop-up window. You can shrink or enlarge the width by modifying this value.

  • height - This is a measure of the height of the pop-up window. You can shrink or enlarge the height by modifying this value.

  • delay - With a small delay value, the pop-up window shows you the entire search process at once. If you would instead like to see the different steps of the search in slow-motion, please select a higher 'delay' value (the exact amount of delay which you will observe depends greatly on the speed of Java as run on your machine).


  • Michael Goldwasser