2014-03-21 21:28

题目:给定一个20GB大小的文本文件,每一行都是一个字符串。请设计方法将这个文件里的字符串排序。

解法:请看下面的注释。

代码:

 // 11.4 Given a file of 20GB containing strings, one word each line. How would you sort them all?
// Answer:
// 1. Split them into 200M pieces.
// 2. For each pieces, use comparison sort or hashing to sort it in memory.
// 3. After sorting each pieces, output it back to a file.
// 4. Merge the 100 pieces with multiprocess, speed up the merging with a heap or something.
// 5. You can't load all full pieces into memory, load one small piece of a piece at a time.
// 6. When this small piece is merged into final result, load the next small piece.
// 7. I suppose it's completely acceptable for a relatively good PC to afford such IO and computation.
int main()
{
return ;
}

《Cracking the Coding Interview》——第11章:排序和搜索——题目4的更多相关文章

  1. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

  2. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  3. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  4. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

  5. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  6. Cracking the Coding Interview(Stacks and Queues)

    Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...

  7. 二刷Cracking the Coding Interview(CC150第五版)

    第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...

  8. 《Cracking the Coding Interview》——第11章:排序和搜索——题目3

    2014-03-21 20:55 题目:给定一个旋转过的升序排序好的数组,不知道旋转了几位.找出其中是否存在某一个值. 解法1:如果数组的元素都不重复,那么我的解法是先找出旋转的偏移量,然后进行带偏移 ...

  9. 《Cracking the Coding Interview》——第11章:排序和搜索——题目2

    2014-03-21 20:49 题目:设计一种排序算法,使得anagram排在一起. 解法:自定义一个comparator,使用额外的空间来统计字母个数,然后比较字母个数. 代码: // 11.2 ...

随机推荐

  1. 笨办法学Python(二十三)

    习题 23: 读代码 上一周你应该已经牢记了你的符号列表.现在你需要将这些运用起来,再花一周的时间,在网上阅读代码.这个任务初看会觉得很艰巨.我将直接把你丢到深水区呆几天,让你竭尽全力去读懂实实在在的 ...

  2. Linux安装 NTFS 支持

    my system kernel Version is 2.6.18-128.el5 在这个地址下载了 kernel-module-ntfs-2.6.18-128.el5-2.1.27-0.rr.10 ...

  3. COGS 146. [USACO Jan08] 贝茜的晨练计划

    ★☆   输入文件:cowrun.in   输出文件:cowrun.out   简单对比时间限制:1 s   内存限制:32 MB 奶牛们打算通过锻炼来培养自己的运动细胞,作为其中的一员,贝茜选择的运 ...

  4. April 25 2017 Week 17 Tuesday

    Have you ever known the theory of chocie? There are a bunch of axiems, but there are only two thing ...

  5. MySQL入门很简单: 5 索引

    1. 索引的含义和特点 索引:创建在表上,是对数据库表中一列或多列的值进行排序的一种结构. 存储类型: B性树(BTREE)索引和哈希(HASH)索引: InnoDB和MyISAM支持BTREE索引, ...

  6. mysql轮廓总结

    架构=数据类型.索引.分片.主从复制原理.数据备份 学习软件,都应该先从架构入手,每一层掌握就行.mysql难吗?从其架构层开始,就不难啦. 架构结构:http://www.cnblogs.com/h ...

  7. vim常用操作整理

    一.删除操作 :%s/r//g 删除DOS方式的回车^M :%s= *$== 删除行尾空白 :%s/^(.*)n1/1$/ 删除重复行 :%s/^.pdf/new.pdf/ 只是删除第一个pdf :% ...

  8. 激活SQLPrompt7.4及以上版本

    SQLPrompt是个很好的sql server提示工具,SQL-SERVER2016只能使用SQLPrompt7.x 以上版本,用激活工具激活后没多久就会检测到激活码不可用.所以感觉是不是有个服务在 ...

  9. 微信端H5页面问题总结

    1.div元素不确定高度的情况下背景图片显示问题,解决后可以自适应不同分辨率的屏幕大小,div元素的background-size设置100%后,其自身的高度和宽度不能再设置. .register-t ...

  10. 1、webpack安装

    1.局部安装: npm i -D (npm install --save-dev的简写) 安装指定版本:npm i -D webpack @version 安装最新版:npm i -D webpack ...