Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Design an algorithm and write code to serialize and deserialize a binary tree/graph

Go down

Design an algorithm and write code to serialize and deserialize a binary tree/graph Empty Design an algorithm and write code to serialize and deserialize a binary tree/graph

Post  Admin Wed Aug 24, 2011 2:10 pm

Serialization:

public static void serialize(TreeNode root, ArrayListNode arr){
if(root.value==null)
arr.add("#");
serialize(root.left,arr);
serialize(root.right,arr);
}


Derialization:

public static void derialization(TreeNode root, ArrayListNode arr){
while(arr.value=="#"){
arr=arr.next;
}
if(arr==null)
return;
TreeNode p=new TreeNode(arr.value);
derialization(root.left,arr.next);
derialization(root.right,arr.next);

}

Admin
Admin

Posts : 131
Join date : 2011-08-16

https://codefornongeek.forumotion.com

Back to top Go down

Design an algorithm and write code to serialize and deserialize a binary tree/graph Empty Re: Design an algorithm and write code to serialize and deserialize a binary tree/graph

Post  Admin Sat Sep 03, 2011 1:30 pm

If the tree is BST, it can be determined by a preorder traversal!

Admin
Admin

Posts : 131
Join date : 2011-08-16

https://codefornongeek.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum