© 1977 by British Computer Society
| ||||||||||||||||||||||||||||||||||||||||||||||||||
A note on the nonrecursive traversal of binary trees
Department of Computer Science, The University of Calgary, 2920 24 Ave. N W, Calgary, Canada
A nonrecursive procedure is developed for traversing unthreaded binary trees in a fixed space and in time proportional to tree size. Burkhard (1975) gives a way to do this without requiring a tag field, but with the requirement that descendent nodes have greater addresses than parents. Knuth (1968) gives a way to do such a traverse but requires a tag field. This paper develops one program that realises either variation (for preorder, symmetric order or endorder traversal for tagged or ordered trees). The development is based on a careful, stepwise rewriting of a simple traversal program, confirming Knuth's claim (1974) that program manipulation is a useful technique for program development.
Received March 1976.
* Department of Computer Science, The University of Calgary, 2920 24 Ave. N W, Calgary, Canada T2N 1N4