How would you recommend traversing a binary search tree to save it in a file. The nodes are sorted alphabetically so that an inorder traversal prints them alphabetically. If I use the same method to save I believe upon loading I will have essentially just created a linked list, instead of a tree.
The words are read from a file, but not in alphabetical order. I know how to do all of the file writing, I just need the best traversal method to store the binary tree. Because if I use inorder traversal, when the file is loaded the tree will look like this:
.
.\
..\
...\
....\
.....\
instead of a somewhat more balanced:
.../\
../\/\
./....\..
........\
If i do inorder traversal, I will only be able to search in On time, whereas if it is balanced i will tend towards Ologn time.