Efficient Array Storage for Binary Tree
问题 We have to write the nodes of a binary tree to a file. What is the most space efficient way of writing a binary tree . We can store it in array format with parent in position i and its children in 2i , 2i+1 . But this will waste lot of space in case of sparse binary trees. 回答1: One method which I like is to store the preorder traversal, but also include the 'null' nodes in there. Storing the 'null' nodes removes the need for also storing the inorder of the tree. Some advantages of this method