November 07, 2024 |3.4K Views

    SDE Sheet - Serialize and Deserialize a Binary Tree

      Share   Like
    Description
    Discussion

    This video is part of the Binary Tree section under GFG SDE Sheet.

    Serialization is to store a tree in an array so that it can be later restored and deserialization is reading tree back from the array. Complete the functions

    • serialize() : stores the tree into an array a and returns the array.
    • deSerialize() : deserializes the array to the tree and returns the root of the tree.

    Note: Multiple nodes can have the same data and the node values are always positive integers. Your code will be correct if the tree returned by deSerialize(serialize(input_tree)) is same as the input tree. Driver code will print the in-order traversal of the tree returned by deSerialize(serialize(input_tree)).

    Example 1:

    Input:       1    /   \   2     3 Output: 
    2 1 3

    Do check out:-
    Problem: https://www.geeksforgeeks.org/problems/serialize-and-deserialize-a-binary-tree/1
    SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/
    Article Link: https://www.geeksforgeeks.org/serialize-deserialize-binary-tree/