Morris Traversal doesn't have O(1) space complexity

All of the solutions (e.g. this) say that Morris Traversal has O(1) space complexity.
Is it really true?

Yes, we don't use additional collections, but we change the given tree. We add new links to it, and the links count is equal to the stack size of the casual depth-first approach.

So, in the worst case, we will add N new links (space complexity O(n)):

        5
       / 
      4   
     / 
    3
   /
  2	
 /
1

And for balanced trees, we will add logn links (space complexity O(logn)).

Why do links in the external collection matter but are inserted in-place not?

Comments (1)