| | |
Summary: PREPRINT. SoftwarePractice and Experience, 21(10):11251128, 1991.
A Note on Searching in a Binary Search Tree
Arne Andersson
Department of Computer Science, Lund University,
BOX 118, S221 00 Lund, Sweden
1
SUMMARY
An algorithm for searching in a binary search tree using twoway comparisons is
presented. The number of comparisons required by this algorithm is only one more
than when using threeway comparisons. Since most highlevel programming lan
guages do not supply threeway comparisons, the number of comparisons used de
facto are reduced by a factor of two. We give experimental results to indicate the
speedup that may be achieved by the presented algorithm.
KEY WORDS: binary search tree, searching, twoway comparison, code optimization
Introduction
An operation which is often assumed to be present when designing algorithms is the
threeway comparison with outcome !, = or ?. An example of an algorithm where
this operation is used is when searching an element in a binary search tree. This is a
fundamental algorithm and it is often presented in various text books and papers [1, 3,
|