Problem. Design serialize(root) → str and deserialize(str) → root so that deserializing a serialized tree gives back
the same tree: same shape, same values. Values are integers (possibly negative).
1
/ \ serialize → "1,2,#,#,3,4,#,#,5,#,#"
2 3 deserialize → the same tree
/ \
4 5
Lessons 10.4 and 10.11 showed the key fact: one traversal with a marker for every empty child identifies a tree uniquely. This lesson turns it into a format: compact, fast to read, safe for deep trees, and robust when the data lives for years.
ML context. Trees get saved constantly: decision trees and gradient-boosted ensembles (exported to JSON, text or ONNX), model architectures and nested configs, parse trees in datasets, prefix trees of tokenizers. A format that's ambiguous, that blows up on unbalanced trees, or that silently changes meaning between versions corrupts models and datasets (Changes C and D).