Visit a tree in O(1) space