I'm having a small problem. I've created a binary tree that represents an n-ary tree using the left-child and right sibling syntax. I know that preorder on the binary tree gives you the same result as if the tree weren't binary. But, how do you change postorder and levelorder so that you don't ruin the order that the n-ary tree would have given you?

7 Years
Discussion Span
Last Post by DeadJustice

You differentiate between logical and actual links. Logical links are part of an n-ary node, but represented with actual binary links. If you can do that, you will be able to figure out how to move when doing any traversal. Red black trees do this well, if you need a real world example. Red links are logical links and black links are actual links, and they come together to represent a 2-3 tree with a binary structure.

Edited by Tom Gunn: n/a


I think I get it. Basically, just retool the logic thinking of how it would usually work in the original tree I think. Hopefully I can figure it out.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.