Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binary Tree Transfer

How to transfer a binary tree (not a balanced tree) across two different systems efficiently, retaining its complete structure?

like image 479
Avinash Avatar asked Aug 31 '10 07:08

Avinash


People also ask

What is binary tree traversal?

Often we wish to process a binary tree by “visiting” each of its nodes, each time performing a specific action such as printing the contents of the node. Any process for visiting all of the nodes in some order is called a traversal.

How do you transfer a tree to another tree?

Algorithm to create a duplicate binary treeCreate a new node and copy data of root node into new node. Recursively, create clone of left sub tree and make it left sub tree of new node. Recursively, create clone of right sub tree and make it right sub tree of new node. Return new node.

How many ways are used to transfer the tree?

Explanation: The three orders of traversal that can be applied to a binary tree are in-order, pre-order and post order traversal.


1 Answers

The obvious way would be to convert your binary tree to an array of nodes, replacing each pointer in the original tree with an index to a node in the array. You can then transmit that array, and on the other end reconstruct a tree with identical structure.

like image 114
Jerry Coffin Avatar answered Oct 07 '22 11:10

Jerry Coffin