Pergunta de entrevista da empresa Amazon

serialize binary tree

Respostas da entrevista

Sigiloso

25 de mai. de 2011

Do something similar to Breadth-First-Traversal. For each node assign an integer key that should be serialized along with the nodes data. Start with 0 as key for the root. For each node with key x, push it's left child (if it exists) with key 2x+1 and it's right child (if it exists) with key 2x+2. The key uniquely identifies position of the node in the tree.

Sigiloso

6 de set. de 2011

Record both pre-order and mid-order sequence

Sigiloso

21 de nov. de 2011

Do the array representation of the tree: children at 2n and 2n+1