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?

Recommended Answers

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.