0% completed
Problem Statement
serialization means converting a data structure or object into a sequence of bits that can be stored or sent over a network. Deserialization is the reverse process, which takes this sequence and recreates the original object or data structure.
Design an algorithm to serialize and deserialize a binary search tree (BST).
The serialization should convert the BST into a string, and deserialization should reconstruct the original BST from this string. There is no restriction on how your serialization/deserialization algorithm should work.
Examples
Example 1:
- Input: root = [4, 2, 6, 1, 3, null, 7]
- Expected Output: [4, 2, 6, 1, 3, null, 7]
- Justification: The output is the same as the input.
Example 2:
- Input: root = [8, 5, 10, 2, null, null, 12]
- Expected Output: [8, 5, 10, 2, null, null, 12]
- Justification: The output is the same as the input.
Example 3:
- Input: root = [15, 10, null, 5, 12, null, null, null, 13]
- Expected Output: [15, 10, null, 5, 12, null, null, null, 13]
- Justification: The output is the same as the input.
Constraints:
- The number of nodes in the tree is in the range [0, 10<sup>4</sup>].
- 0 <= Node.val <= 10<sup>4</sup>
- The input tree is guaranteed to be a binary search tree.
Try it yourself
Try solving this question here:
.....
.....
.....
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible