I'm not sure if this is what you are looking for, but I once came up with a way to save a binary tree in such a way that when it is rebuilt, it will be balanced. You don't get back the exact same tree with all the nodes in the same position, but you do get the same nodes in a balanced configuration.
Start by doing an inorder traversal and storing each node sequentially in an array. Then call a recursive function called saveTree(first, last), where first and last are the first and last indices of the array. saveTree does the following if: write middle item of array to the file call saveTree on left half of array call saveTree on right half of array When you rebuild the tree adding the nodes in the order in which they occur in the file, the resulting tree will be balanced. Don On Aug 28, 1:29 am, rohit <[email protected]> wrote: > How to save a binary search tree space efficiently and built it > again , just tell any idea. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
