Good evening! Here's our prompt for today.
Given a binary tree representation, can you come up with a method to serialize the tree and then deserialize it to get the exact same tree?

What is Serialization and Deserialization?
Serialization is a process that converts a data structure to a suitable format that can be stored either on a file or in memory. It can also be a format for data transmission across a network. Deserialization is the reverse process of recovering the original data structure. In this tutorial, I will show you how you can convert a binary tree with integer keys into an integer array and vice versa. You can then save the integer array in a text or binary file. You can also convert this integer array into a suitable format for data transmission over a network.
There are many ways of serializing a binary tree. Most of the methods involve traversing the tree, while storing each key in a data structure. Understanding a traversal is therefore the key to understanding the serialization and its reverse deserialization process. In this tutorial, we'll look at preorder traversal and how it can be used for serializing and deserializing a binary tree.
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx
assert.equal(serialized, '5 10 17 e e 3 e e 8 e e ');
var assert = require('assert');
​
function serialize(root) {
// fill in this method
return {};
}
​
function deserialize(data) {
// fill in this method
return {};
}
​
function Node(val) {
this.val = val;
this.left = null;
this.right = null;
}
​
// Regular binary trees
var tree1 = new Node(4);
tree1.left = new Node(1);
tree1.right = new Node(3);
​
var tree2 = new Node(5);
tree2.left = new Node(10);
tree2.left.left = new Node(17);
tree2.left.right = new Node(3);
tree2.right = new Node(8);
​
Here's how we would solve this problem...
How do I use this guide?