From f7dc8af9c4a95f06475a7c3adbb5aafc7a26466d Mon Sep 17 00:00:00 2001 From: bt3gl <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Tue, 8 Aug 2023 15:00:00 -0700 Subject: [PATCH] Delete bt_serialization.py --- trees/bt_serialization.py | 47 --------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 trees/bt_serialization.py diff --git a/trees/bt_serialization.py b/trees/bt_serialization.py deleted file mode 100644 index 62ea148..0000000 --- a/trees/bt_serialization.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# author: bt3gl - -''' -Serialization is the process of converting a data structure or object into -a sequence of bits so that it can be stored in a file or memory buffer, or -transmitted across a network connection link to be reconstructed later in -the same or another computer environment. - -Design an algorithm to serialize and deserialize a binary tree. There is no -restriction on how your serialization/deserialization algorithm should work. -You just need to ensure that a binary tree can be serialized to a string and -this string can be deserialized to the original tree structure. -''' - - -class Codec: - - def serialize(self, root): - - def helper(root, string): - if root is None: - string += 'None,' - else: - string += str(root.val) + ',' - string = helper(root.left, string) - string = helper(root.right, string) - return string - - return helper(root, '') - - def deserialize(self, data): - - def helper(data): - if data[0] == 'None': - data.pop(0) - return None - root_val = data.pop(0) - root = TreeNode(root_val) - root.left = helper(data) - root.right = helper(data) - return root - - root = helper(data.split(',')) - - return root