Careercup - Google面试题 - 5765091433644032
2014-05-08 09:32
原题:
Given a binary tree, how would you copy it from one machine to the other, assume you have a flash drive. I believe we should write the binary tree to file and have the other machine de-serialize it. But how should we do it?
题目:如何序列化和反序列化一颗二叉树。
解法:做法当然有很多种,但基本都是基于某种遍历方式去进行文本或者二进制的表示。文本比较直观,不过二进制的序列化应该在空间上更有效率。我的思路是前序遍历,并用一个特殊符号来标记空指针。用括号来表示一颗完整的树,这样就能递归进行序列化/反序列化了。好像之前刚做了个一样的题,所以这题没有写代码。
代码:
// http://www.careercup.com/question?id=5765091433644032
// Transfer a binary tree to another machine? Of course, serialization and deserialization.
// Any kind of tree traversal with the help of a special notation to represent 'NULL' can do the serialization.
// For example, preorder traversal for the tree below:
// 1
// / \
// 2 8
// / \ / \
// 7 12 34 9
//
// If we use '#' to represent NULL, the preorder traversal looks like {1, 2, 7, #, #, 12, #, #, 8, 34, #, #, 9, #, #}
// With this you can output the array to a text file.
// The '#' notation ensures that every binary tree has its unique preorder traversal.
int main()
{
return ;
}
Careercup - Google面试题 - 5765091433644032的更多相关文章
- Careercup - Google面试题 - 5732809947742208
2014-05-03 22:10 题目链接 原题: Given a dictionary, and a list of letters ( or consider as a string), find ...
- Careercup - Google面试题 - 5085331422445568
2014-05-08 23:45 题目链接 原题: How would you use Dijkstra's algorithm to solve travel salesman problem, w ...
- Careercup - Google面试题 - 4847954317803520
2014-05-08 21:33 题目链接 原题: largest number that an int variable can fit given a memory of certain size ...
- Careercup - Google面试题 - 6332750214725632
2014-05-06 10:18 题目链接 原题: Given a ,) (,) (,), (,) should be returned. Some suggest to use Interval T ...
- Careercup - Google面试题 - 5634470967246848
2014-05-06 07:11 题目链接 原题: Find a shortest path ,) to (N,N), assume is destination, use memorization ...
- Careercup - Google面试题 - 5680330589601792
2014-05-08 23:18 题目链接 原题: If you have data coming in rapid succession what is the best way of dealin ...
- Careercup - Google面试题 - 5424071030341632
2014-05-08 22:55 题目链接 原题: Given a list of strings. Produce a list of the longest common suffixes. If ...
- Careercup - Google面试题 - 5377673471721472
2014-05-08 22:42 题目链接 原题: How would you split a search query across multiple machines? 题目:如何把一个搜索que ...
- Careercup - Google面试题 - 6331648220069888
2014-05-08 22:27 题目链接 原题: What's the tracking algorithm of nearest location to some friends that are ...
随机推荐
- MySQL允许远程访问
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option; flush privileges; ...
- [原]Hrbust1053 Warcraft III (完全背包)
本文出自:http://blog.csdn.net/svitter 原题:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProbl ...
- vim 文字插入
我们知道VIM中,普通的复制和粘贴都是YY和PP.那么怎么将vim以外的文件插入到vim编辑器中呢!这是个问题: 首先我们要选中想要插入的文字,如: 然后进入vim插入模式:SHIFT + Inser ...
- Aspose插件
Eclipse安装地址: http://apps.aspose.com/marketplace/eclipse/asposewizardrepo
- C#局域网桌面共享软件制作(二)
链接C#局域网桌面共享软件制作(一) 如果你运行这个软件查看流量监控就会发现1~2M/s左右的上传下载,并且有时会报错“参数无效”,如果你将屏幕截图保存到本地的话每张图片大概4M(bmp).120KB ...
- Redis监控方案
Redis 监控最直接的方法当然就是使用系统提供的 info 命令来做了,你只需要执行下面一条命令,就能获得 Redis 系统的状态报告. redis-cli info 内存使用 如果 Redis 使 ...
- Mysql常用数据类型详细说明及实例说明(学习笔记一)
1.Mysql 在windows下 Net start mysql[启动] Net stop mysql[停止] Quit[退出mysql命令行] \c[取消输入的命令] Select version ...
- Yii框架中使用PHPExcel导出Excel文件
最近在研究PHP的Yii框架,很喜欢,碰到导出Excel的问题,研究了一下,就有了下面的方法: 1.首先在config\main.php中添加对PHPExcel的引用,我的方式是这样: 1 2 3 4 ...
- ERROR 1045 (28000): Access denied for user root@localhost (using password:
错误描述: Mysql中添加用户之后可能出现登录时提示ERROR 1045 (28000): Access denied for user的错误.删除user.user中值为NULL的,或更新NULL ...
- 获取android SDCard存储大小
//File path = Environment.getDataDirectory();//手机内置空间 1.获取SD卡的路径 File path = Environment.getExternal ...