Loading section...

Serialization and Deserialization of Trees

Concepts: pySerialize, pyDeserialize, pyTreeCheckpoint

Serialization means converting a tree in memory into a string that can be stored or transmitted. Deserialization means reconstructing the tree from that string. This is LeetCode 297 and it is a common final-round problem because it requires combining BFS (for encoding) with careful state management (for decoding). In DE, it maps directly to persisting query plan trees, storing DAG state for checkpoint/restart, or serializing schema trees. BFS-Based Serialization The key insight in deserialization: the BFS queue processes parents in the same order they were serialized. For every parent we dequeue, the next two values in the string are its left and right children. This 1:1 correspondence between queue order and serialized order is what makes the reconstruction deterministic. There is no ambi