[algogeeks] Saving and restoring Binary trees in files

2013-11-08 Thread kumar raja
What is the effective way to save and restore the binary trees to files
effectively?













Regards,
Kumar Raja.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


[algogeeks] Re: Saving and restoring Binary trees in files

2013-11-08 Thread Don
Save it in pre-order.
Rebuild by inserting nodes in the order they occur in the file.

On Friday, November 8, 2013 8:33:19 AM UTC-5, kumar raja wrote:

 What is the effective way to save and restore the binary trees to files 
 effectively?













 Regards,
 Kumar Raja.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Re: Saving and restoring Binary trees in files

2013-11-08 Thread Vishnu
1) save the nodes(value, left and right pointer) in pre-order traversal
2) also save pointers of all node in same order

to restore
1) create new N nodes
2) do pointer mapping from old - new
3) restore nodes and replace old pointers to new


On Fri, Nov 8, 2013 at 8:50 PM, Don dondod...@gmail.com wrote:

 Save it in pre-order.
 Rebuild by inserting nodes in the order they occur in the file.


 On Friday, November 8, 2013 8:33:19 AM UTC-5, kumar raja wrote:

 What is the effective way to save and restore the binary trees to files
 effectively?













 Regards,
 Kumar Raja.

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.




-- 
Thanks,
Vishnu

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Re: [algogeeks] Re: Saving and restoring Binary trees in files

2013-11-08 Thread atul anand
@don :  it is not BST ,  it is binary tree ...so your approach will
not work in this case.

@kumar : save pre-order and in-order traversal with some delimiter in
b/w traversals.

pre-order : a b c d e
in-order   : c b e a d

write in file :-

a b c d e # c b e a d

now use pre-order and in-order traversal to re-create binary tree.

2) consider null node as # ..now write in file preorder traversal.

for eg :  a b c # # # d # #

3) save level order traversal of binary tree, where each level uses
# to distinguish between levels and * to mark null nodes
eg : a # b c # e *
a - level 1
b c - level 2
e NULL - level 3

shortcoming in 2 and 3 is use of character that can be part of tree
itself.So if node can contain # then you have to use some other
character to distinguish.

for solution 1 , you can write traversal in 2 lines instead of using #

On 11/8/13, Vishnu vishnu...@gmail.com wrote:
 1) save the nodes(value, left and right pointer) in pre-order traversal
 2) also save pointers of all node in same order

 to restore
 1) create new N nodes
 2) do pointer mapping from old - new
 3) restore nodes and replace old pointers to new


 On Fri, Nov 8, 2013 at 8:50 PM, Don dondod...@gmail.com wrote:

 Save it in pre-order.
 Rebuild by inserting nodes in the order they occur in the file.


 On Friday, November 8, 2013 8:33:19 AM UTC-5, kumar raja wrote:

 What is the effective way to save and restore the binary trees to files
 effectively?













 Regards,
 Kumar Raja.

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.




 --
 Thanks,
 Vishnu

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.