Maintaing list order in binary tree.

Posted by TheBigO on Stack Overflow See other posts from Stack Overflow or by TheBigO
Published on 2011-02-16T23:16:59Z Indexed on 2011/02/16 23:25 UTC
Read the original article Hit count: 263

Filed under:
|

Given a sequence of numbers, I want to insert the numbers into a balanced binary tree such that when I do a preorder traversal on the tree, it gives me the sequence back.

How can I construct the insert method corresponding to this requirement?

Remember that the tree must be balanced, so there isn't a completely trivial solution. I was trying to do this with a modified version of an AVL tree, but I'm not sure if this can work out.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about binary-trees