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

View previous topic View next topic Go down

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

Post  Admin on 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

View user profile http://codefornongeek.forumotion.com

Back to top Go down

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

Post  Admin on 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

View user profile http://codefornongeek.forumotion.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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