Coding Problem #3

Problem #3

Let’s do this!

Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string back into the tree.

For example, given the following Node class

class Node:
    def __init__(self, val, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

The following test should pass:

node = Node('root', Node('left', Node('left.left')), Node('right'))
assert deserialize(serialize(node)).left.left.val == 'left.left'


Ok, I’ll be the first to admit that I have NEVER done a problem like this. Root to a binary tree? What are they even talking about? Based on my LIMITED understanding of Binary Trees.. I could attempt to solve this problem now, or wait until I’ve read up on these from This site is all about me figuring out things for myself, so I might try to work through this on my own.

Stay Tuned for a solution to follow!


Leave a Reply