Python In-order Binary Tree Traversal
September 23, 2009

Comparison on a dual-core 2.00 Ghz Pentium with 2 Gig RAM
These comparisons were done in Python. Source available at the following site: details of options, figures, and source.

In-order Tree traversal options:

Storage costs

O(log n) additional memroy: Recursion (1) and modified stack (3, 3b, 4) require overhead on the order of the depth of the tree, so these methods are comparable.

O(n) additional memory: Visited flag (2) and parent pointer (5, 6, 6b) require additional memory on the order of the tree size, so those require relatively more memory than O(lg n) storage methods.

Computation cost

All methods are O(N) and visit each node 1 to 3 times (additional visits when coming back up from each child). Thus, the difference is in the constants and may depend on the programming language. Table of the results and graph available on a different page link.

Conclusions

Note that these measurements are influenced by the computer architecture and programming language (Python).

So it seems recursion is the way to go. It is the simplest to code, executes quickly, and uses low additional storage (O(lg n) is the least for the methods compared.)