Search Algorithms Demo

As the search algorithm is executed in the applet to the right, the list item currently being probed is highlighted. Following an unsuccessful probe, the searched portion of the list is hidden leaving only the unsearched portion visible. With a linear search, the length of the unsearched portion of the list is decreased by one with each probe.  With a binary search, the length is cut in half with each probe.

When the search is complete, the index at which the target value was found is displayed. Remember that an index of -1 indicates that the target was not found in the list.

You may choose to use either the linear or the binary search algorithm. Just remember that, in general, a binary search does not work on unsorted lists.

To speed up or slow down the action, choose a different time delay. Long delays are good for the binary search but make the linear search excruciatingly slow.

ALT="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." Your browser is ignoring the <APPLET> tag!