• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
May 04, 2024 |720 Views
PROBLEM OF THE DAY: 02/05/24 - Serialize and deserialize a binary tree
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Binary Tree but also build up problem-solving skills.

In this problem, we are given to 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 :

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

Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/serialize-and-deserialize-a-binary-tree/1