3 ms·
I agree. I would also point out that this doesn't have much advantage (if it has any) over simple recursion, performance wise. First, the depth (the amount of
by lmilcin 7y ago
I agree. I would also point out that this doesn't have much advantage (if it has any) over simple recursion, performance wise.
First, the depth (the amount of storage for traversal) typically is on the order of log2(n) and so this gets amortized very quickly when traversing nodes.
What if the tree is unbalanced?
If the tree is unbalanced you will have all sorts of other problems like problems with inserting or searching. Since trees are typically used for efficient searching and traversal is done more efficiently with just plain array (or list) it is really hard to find any real-world trees that are not kept balanced somehow.