《Cracking the Coding Interview》——第11章:排序和搜索——题目4
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的更多相关文章
- Cracking the coding interview 第一章问题及解答
Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...
- 《Cracking the Coding Interview》读书笔记
<Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...
- Cracking the coding interview
写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...
- Cracking the coding interview目录及资料收集
前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...
- Cracking the Coding Interview(Trees and Graphs)
Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...
- 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 ...
- 二刷Cracking the Coding Interview(CC150第五版)
第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...
- 《Cracking the Coding Interview》——第11章:排序和搜索——题目3
2014-03-21 20:55 题目:给定一个旋转过的升序排序好的数组,不知道旋转了几位.找出其中是否存在某一个值. 解法1:如果数组的元素都不重复,那么我的解法是先找出旋转的偏移量,然后进行带偏移 ...
- 《Cracking the Coding Interview》——第11章:排序和搜索——题目2
2014-03-21 20:49 题目:设计一种排序算法,使得anagram排在一起. 解法:自定义一个comparator,使用额外的空间来统计字母个数,然后比较字母个数. 代码: // 11.2 ...
随机推荐
- 332. Reconstruct Itinerary (leetcode)
1. build the graph and then dfs -- graph <String, List<String>>, (the value is sorted a ...
- IOS 打开照相机 打开相册
/** * 打开照相机 */ - (void)openCamera { if (![UIImagePickerController isSourceTypeAvailable:UIImagePicke ...
- TypeScript学习-TypeScript环境配置
http://blog.csdn.net/shi_weihappy/article/details/49332091
- 复式记账中"借"与"贷"的理解
财务常识中,复式记账法应用极广,公司采用的是它的借贷记账法.因此,深刻的理解"借"与"贷"的含义极其重要. 一切从历史说起. 起源: Credit 英文含义 ...
- js日期转换Fri Oct 31 18:00:00 UTC+0800 2008转换为yyyy-mm-dd
Date.prototype.Format = function (fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d ...
- 《JavaScript高级程序设计第三版》——细碎知识痛点整理(第六章)
面向对象的程序设计 对象是一组没有特定顺序的值6.1.1 属性类型ECMAScript中有两种属性:数据属性和访问器属性.1. 数据属性Configurable 表示能否通过delete删除属性从而重 ...
- ES6介绍
1.ES6简介 ECMAScript 6.0,是 JavaScript 语言下一代标准,发布于 2015 年 6 月.它的目标是使得 JavaScript 语言可以用来编写复杂的大型应用程序,成为企业 ...
- java自定义泛型 面试题:接收任意数组进行反转 泛型通配符
不用泛型只能操作某种类型进行反转 代码如下: package com.swift.fanxing; import org.junit.Test; public class RenyiReverse { ...
- JAVA / MySql 编程——第二章 初始MySQL
1. MySQL: ● MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司. MySQL最流行的关系型数据库管理系统, ...
- IOS中input与fixed同时存在的情况会出现bug
两种解决方案,一种是将内容区域放在中间部分,只是中间部分在滚动(还是固定在底部):另一种是判断当是ios时,将其转换为absolute定位.(跟随着页面的滚动而滚动);; 当使用input时,fixe ...