in DS
56 views
0 votes
In a program, you build a tree(non-empty) according to some inputs in the program. Now you have to shutdown your computer and the next day you need to work on this already build tree(do not build the tree again from scratch). How would you store, save or do something else to get the already build tree? The tree can be binary or non-binary but non-empty. Give a detailed explanation.
in DS
by
56 views

3 Comments

at the end of the program, save your tree in a file.

at the starting of the program, loading from file.

 

Hope this will work
0
Can you explain it? like, what are the possible formats to save the tree in the file? Assume tree node contains ASCII type data.
0
how to save the tree - at the end of the program, we will have only one tree. So print the inorder and preorder in a file.

 

so, in our program, at the beginning of the our actual program,

1) open the file

2) construct tree using inorder+preorder

3) run remaining actual program

 

at the end of our actual program,

1) open the file

2) delete existing content

3) write inorder + preorder of the tree

4) save and close.
0

Subscribe to GO Classes for GATE CSE 2022

Please log in or register to answer this question.

Related questions