Use in-order traversal to serialize.
Given in-order [2, 1, 4, 3, 5], you can't reconstruct the tree uniquely. You don't know where the root is or how the nodes are arranged.
You need to encode the structure, not just the values.
The trap
Use in-order traversal to serialize.
Given in-order [2, 1, 4, 3, 5], you can't reconstruct the tree uniquely. You don't know where the root is or how the nodes are arranged.
You need to encode the structure, not just the values.