@@ -39,3 +39,48 @@ def dfs():
3939 return node
4040
4141 return dfs ()
42+
43+
44+ # Binary Tree Serialization Techniques
45+
46+ # Example Tree:
47+ # 1
48+ # / \
49+ # 2 3
50+ # / \
51+ # 4 5
52+
53+ # 1. Preorder with Null Markers (This Implementation)
54+ # Visit: root → left → right, mark nulls with '#'
55+ # Result: "1,2,#,#,3,4,#,#,5,#,#"
56+ # Pros: Self-contained, unambiguous, O(n) reconstruction
57+ # Cons: Longer string due to null markers
58+
59+ # 2. Level-order (BFS) with Null Markers
60+ # Visit level by level, mark nulls with '#'
61+ # Result: "1,2,3,#,#,4,5"
62+ # Pros: Simple format like preorder, level-by-level intuitive
63+ # Cons: Still requires queue processing
64+
65+ # 3. Postorder with Null Markers
66+ # Visit: left → right → root
67+ # Result: "#,#,2,#,#,4,#,#,5,3,1"
68+ # Pros: Bottom-up reconstruction
69+ # Cons: Less intuitive than preorder
70+
71+ # 4. Inorder + Preorder (Two Arrays)
72+ # Inorder: [2,1,4,3,5], Preorder: [1,2,3,4,5]
73+ # Pros: Works for any binary tree structure
74+ # Cons: Requires two arrays, only works with unique values
75+
76+ # 5. Parenthetical Preorder
77+ # Same traversal as #1 but with parentheses format: value(left)(right)
78+ # Result: "1(2()())(3(4()())(5()()))"
79+ # Pros: Human readable structure, shows nesting clearly
80+ # Cons: Complex parsing, verbose
81+
82+ # 6. Parenthetical Postorder
83+ # Same traversal as #3 but with parentheses format: (left)(right)value
84+ # Result: "(()()2)((()()4)(()()5)3)1"
85+ # Pros: Bottom-up readable structure
86+ # Cons: Even more complex parsing
0 commit comments