Book Review of “The practice of programming” (Ⅲ)
The practice of programming
Chapter 3 Design and Implementation
In this section, we focus on one kind problem: generate random English text that reads well.
The solution is called 'The Markov Chain Algorithm', and its main idea is shown as follows:
First we scan an article and save it in a special chart. For example, we use two adjacent words as prefix, by searching which we can get all the possible following words. We use 'hashtable', 'list', 'vector' to realize this function. The details are left out.
Then we are to generate a paragraph based on the data above. The first several words are picked up randomly. And each time, we choose one of its suffix randomly. To ensure the random in just one scanning, we use a stractage, that is, 'use a variable "n" to count the current number of suffixes, use a string to save the previous chosen suffix. each time the present suffix can replace the previous suffix by the possibilition 1/n. When the scan is over, the suffix chosen is determined.'
Last, to limit to total length of the generated paragraph, we add a symbol of ending to each prefix's map. Also, use a variable to count to total length we have generated.
The book introduce the solving programs in C, JAVA, C++, Awk, Perl. Their different realizations are all anchored in the same main idea. By comparison, we can found that C has the longest code lines and the highest efficience. Awk and Perl are the easiest. The quickest is C, then is Perl. Their adjustence is also different. If the number of prefix is changed, C, C++, Java is easy to modefy, while Perl and Awk are not.
Book Review of “The practice of programming” (Ⅲ)的更多相关文章
- Book Review of “The practice of programming” (Ⅳ)
The practice of programming Chapter 4 Interfaces A good programmer should always be good at designin ...
- Book Review of “The practice of programming” (Ⅱ)
The practice of programming Chapter 2 Algorithms and Data Structures Searching sequential search (li ...
- Book Review of "The Practice of Programming" (Ⅰ)
The Practice of Programming In the preface, the author illustrates four basic principles of programm ...
- 2015年第2本(英文第1本):《The Practice of Programming》
2015年计划透析10本英文原著,最开始选定的第一本英文书是<Who Moved my Cheese>,可是这本书实在是太短.太简单了,总体的意思就是要顺应变化,要跳出自己的舒适区,全文不 ...
- net programming guid
Beej's Guide to Network Programming Using Internet Sockets Brian "Beej Jorgensen" Hallbeej ...
- FRP represents an intersection of two programming paradigms.
FRP represents an intersection of two programming paradigms. Functional programming Functional progr ...
- [转]9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路
1,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也作为之前三个半月的求职的回顾. 首先说说我拿到的offer情况: 微软,3面->终面,搞定 百度,3面->终面,口头of ...
- 9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路
1,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也作为之前三个半月的求职的回顾. 首先说说我拿到的offer情况: 微软,3面->终面,搞定 百度,3面->终面,口头of ...
- (转)9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路
原文:http://www.cnblogs.com/figure9/archive/2013/01/09/2853649.html 1,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也 ...
随机推荐
- Docker入门与应用系列(五)Dockerfile
Dockerfile是为快速构建docker image而设计的,当你使用dockerbuild 命令的时候,docker 会读取当前目录下的命名为Dockerfile(首字母大写)的纯文本文件并执行 ...
- java 包冲突解决方法
1.诊断包冲突 java.lang.NoSuchMethodError: org.apache.commons.io.output.DeferredFileOutputStream.<init& ...
- Havel-Hakimi定理(推断是否可图序列)
给定一个非负整数序列{dn},若存在一个无向图使得图中各点的度与此序列一一相应.则称此序列可图化.进一步.若图为简单图,则称此序列可简单图化 至于能不能依据这个序列构造一个图,就须要依据Havel-H ...
- 标C编程笔记day05 函数声明、文件读写、联合类型、枚举类型
函数声明: 1.隐式声明:在没有声明的情况下,系统可依据參数类型推断去调用函数(有可能出错) 2.显式声明:声明在被调用之前.如:double add(double,double); ...
- 五月的仓颉大神写的 三年java程序员面试感悟 值得分享给大家
感谢 五月的仓颉 的这篇文章 , 让我重新认识到自己身上的不足之处 . 原文地址http://www.cnblogs.com/xrq730/p/5260294.html,转载请注明出处,谢谢! 前 ...
- C++获取某个文件夹下的所有文件
获取某个文件夹下的所有文件,返回各文件的路径加文件名 path为某文件夹的路径:eg. char * filePath = "C:\\Users\\WUQP\\Desktop\\test_d ...
- 选项卡jQuery(ele).each()
$("li").each(index){ $(this).mouseover(fucntion(){ $("div.contentin" ...
- Django Signal 代码布局
需要确保信号注册函数在使用前就被引入,所以理论上你可以将其置于满足上述条件的任意位置. 官方推荐 将信号处理器定义在关联 app 目录下的 signals.py 中,在关联 app 的 apps.Ap ...
- 百度 url 当在baidu搜索结果展示页,去点击标头时
Spencer : 百度加一层跳转主要为了监控点击 w 基于dns和用户体验考虑的猜测 0-百度自己的cdn服务器存入各个域名/url的服务器ip(多ip情况下,返回物理空间相对用户最近的服务器ip) ...
- python基础之类的进阶
一.__setitem__,__getitem,__delitem__ #把对象操作属性模拟成字典的格式 class Foo: def __init__(self,name): self.name=n ...