Serialize and Deserialize Binary Tree — C# Coding Problem
Difficulty: hard | Category: tree
Problem Description
Design an algorithm to serialize and deserialize a binary tree. Serialization is the process of converting a tree to a string; deserialization is the reverse. Implement two functions: - `serialize(root)` — returns a string representation of the tree - `deserialize(data)` — reconstructs the tree from that string There is no restriction on how your serialization/deserialization algorithm should work. Just ensure that a binary tree can be serialized to a string and this string can be deserialized back to the original tree structure.
Examples
Example 1
Input: root = [1,2,3,null,null,4,5]
Output: [1,2,3,null,null,4,5]
Explanation: serialize then deserialize should return the original tree.