I went to an interview today where I was asked to serialize a binary tree. I implemented an array-based approach where the children of node i (numbering in level-order trave
The best way is to use a special char (like # as previous comment mentioned) as sentinel. It's better than constructing an inorder traversal array and a preorder/postorder traversal array, both in space complexity wise and time complexity wise. it's also way easier to implement.
Linked list is not a good fit here since in order to reconstruct the tree, you better have const element access time