
Given the root of a binary tree, implement two functions: one to serialize the tree into a string and one to deserialize that string back into the original binary tree. The encoding must preserve both node values and tree structure, including missing children.
Example 1:
Input: root = [1,2,3,null,null,4,5]
Output: "1,2,3,#,#,4,5,#,#,#,#"
Explanation: A preorder traversal with `#` markers for null children preserves the exact tree shape.
Example 2:
Input: root = []
Output: "#"
Explanation: An empty tree is represented by a single null marker.
0 <= number of nodes <= 10^4-1000 <= Node.val <= 1000root = [1,2,3,null,null,4,5]Output"1,2,#,#,3,4,#,#,5,#,#"WhyPreorder traversal writes each node and uses `#` for missing children, preserving the exact shape.root = []Output"#"WhyAn empty tree is represented by a single null marker.root = [7]Output"7,#,#"WhyA single node has two null children, both of which must be encoded.0 <= number of nodes <= 10^4-1000 <= Node.val <= 1000The tree may be skewed or balancedThe serialized representation must support exact reconstructiondef serialize_deserialize(root):