How to Serialize Binary Tree

Posted by Veljko Skarich on Stack Overflow See other posts from Stack Overflow or by Veljko Skarich
Published on 2011-01-06T03:48:45Z Indexed on 2011/01/06 3:54 UTC
Read the original article Hit count: 324

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 traversal) were at the 2*i index for the left child and 2*i + 1 for the right child. The interviewer seemed more or less pleased, but I'm wondering what serialize means exactly? Does it specifically pertain to flattening the tree for writing to disk, or would serializing a tree also include just turning the tree into a linked list, say. Also, how would we go about flattening the tree into a (doubly) linked list, and then reconstructing it? Can you recreate the exact structure of the tree from the linked list? Thank you/

© Stack Overflow or respective owner

Related posts about serialization

Related posts about tree