Question
Design an algorithm to serialize and deserialize a binary tree. You just need to ensure that a binary tree can be serialized to a
Design an algorithm to serialize and deserialize a binary tree. 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. In the BinaryTree class, add a method preorder_serialize() to serialize the binary tree and return the serialized string by using the preoreder traversal. For example, the binary tree to be serialized is: Serialization 10 12 20 14 22 File Deserialization 12 20 10 14 22 a. The preorder_serialize() method should use the preorder traversal and return the string "20, 8, 4, None, None, 12, 10, None, None, 14, None, None, 22, None, None". (40 pts) b. In Binary Tree, add a method save(string) to write the string into a text file and name it your Lastname_Firstname.csv. (10 pts) c. In BinaryTree, add a method retrieve() to read the string from your text file and return the string. (10 pts) d. In BinaryTree.java, add a method pre_order_deserialize(string) that accepts a serialized string, deserializes the given string to the original binary tree, and returns the tree. (40 pts)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started