[Google面试]10G的数据如何用2G的空间找到中位数(Median)
2015-03-29 12:57
309 查看
Stack Overflow上面的解答,简直是赞:
Create an 8-byte array with 2^16 entries. Take your input numbers, shift off the bottom sixteen bits, and create a histogram. (That said, each bin is the count of that number)
Now you count up in that histogram until you reach the bin that covers the midpoint of the values.
Pass through again, ignoring all numbers that don’t have that same set of top bits, and make a histogram of the bottom bits.
Count up through that histogram until you reach the bin that covers the midpoint of the (entire list of) values.
Now you know the median, in O(n) time and O(1) space (in practice, under 1 MB).
Create an 8-byte array with 2^16 entries. Take your input numbers, shift off the bottom sixteen bits, and create a histogram. (That said, each bin is the count of that number)
Now you count up in that histogram until you reach the bin that covers the midpoint of the values.
Pass through again, ignoring all numbers that don’t have that same set of top bits, and make a histogram of the bottom bits.
Count up through that histogram until you reach the bin that covers the midpoint of the (entire list of) values.
Now you know the median, in O(n) time and O(1) space (in practice, under 1 MB).
相关文章推荐
- 10G数据量,只有2G内存,怎样找到中位数?
- 10G数据量,只有2G内存,怎样找到中位数?
- 如何找到使用中位数星火(How to find median using Spark)
- 不开辟用于交换数据的临时空间,如何完成字符串的逆序(在技术一轮面试中,有些面试官会这样问)
- 面试:不开辟用于交换数据的临时空间,如何完成字符串的逆序
- 找到好工作的第一关-如何面试
- 如何将EXP出来的数据IMP进不同的表空间
- Google女工程师:如何准备Google面试
- Google员工出书大谈如何通过面试关
- ora-01652问题 oracle 如何缩小和重建temp表空间的数据文件
- oracle 10g 数据如何导入到oracle 9i中?
- Google:如何准备软件工程师的面试
- 如何把数据导入不同的表空间?
- 如何把数据导入不同的表空间?
- Google女性工程师揭密:如何准备Google软件工程师面试
- C/C++面试之算法系列--如何实现用更少的空间表示英文字母(a ~ z)构成char A[n]字符串
- 计算机面试笔试题——如何找到最合适的女朋友
- 浅入浅出Oracle Spatial GeoRaster 10g影像数据管理(3)——空间参考(Georeferencing)
- 如何将多个表空间的数据导入到单个表空间(USER_A到USER_B)
- Google女性工程师揭密:如何准备Google软件工程师面试