究竟如何序列化 BST?以最有效的方式做到这一点的正确方法是什么?现在,这太笼统了,所以让我解释一下我的意思。
这是一些伪伪代码:
public int[] serialize(root){
preorder traversal
convert node to binary representation
add the binary representation to an array
send array via stream
}
或者
public int serialize(root){
preorder traversal
convert node to binary representation
send the binary representation via stream
}
我的问题是——创建一个数组并发送充满比特的数组,这样高效吗?或者我应该跳过整个数组的想法,每次转换一个节点时,将它发送出去反序列化吗?也许这两种实现方式都是愚蠢的。任何帮助将不胜感激。
最佳答案
我建议您也看看 google protocol buffers https://developers.google.com/protocol-buffers/docs/overview
关于java - 序列化二叉搜索树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12047568/