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” (Ⅲ)的更多相关文章

  1. Book Review of “The practice of programming” (Ⅳ)

    The practice of programming Chapter 4 Interfaces A good programmer should always be good at designin ...

  2. Book Review of “The practice of programming” (Ⅱ)

    The practice of programming Chapter 2 Algorithms and Data Structures Searching sequential search (li ...

  3. Book Review of "The Practice of Programming" (Ⅰ)

    The Practice of Programming In the preface, the author illustrates four basic principles of programm ...

  4. 2015年第2本(英文第1本):《The Practice of Programming》

    2015年计划透析10本英文原著,最开始选定的第一本英文书是<Who Moved my Cheese>,可是这本书实在是太短.太简单了,总体的意思就是要顺应变化,要跳出自己的舒适区,全文不 ...

  5. net programming guid

    Beej's Guide to Network Programming Using Internet Sockets Brian "Beej Jorgensen" Hallbeej ...

  6. FRP represents an intersection of two programming paradigms.

    FRP represents an intersection of two programming paradigms. Functional programming Functional progr ...

  7. [转]9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路

    1,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也作为之前三个半月的求职的回顾. 首先说说我拿到的offer情况: 微软,3面->终面,搞定 百度,3面->终面,口头of ...

  8. 9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路

    1,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也作为之前三个半月的求职的回顾. 首先说说我拿到的offer情况: 微软,3面->终面,搞定 百度,3面->终面,口头of ...

  9. (转)9个offer,12家公司,35场面试,从微软到谷歌,应届计算机毕业生的2012求职之路

    原文:http://www.cnblogs.com/figure9/archive/2013/01/09/2853649.html 1,简介 毕业答辩搞定,总算可以闲一段时间,把这段求职经历写出来,也 ...

随机推荐

  1. 剑指offer(13)-栈的压入、弹出序列 九度1366

    题目来自剑指offer系列 九度 1366:http://ac.jobdu.com/problem.php?pid=1367 题目描述: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列 ...

  2. hdu 4539(状压dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4539 思路:跟poj1185简直就是如出一辙! #include<iostream> #i ...

  3. 解决finalflares 安装成功后无法显示问题

    按照网上的安装方法:http://blog.sina.com.cn/s/blog_e9370eb80101gias.html 安装插件并破解,安装过程没有任何错误,但是打开max2012始终看不到这个 ...

  4. Array转为Json需要导入的包

    今天自己写了一个JSON的例子,可以一调用就出了问题,报下面这个异常: java.lang.ClassNotFoundException: org.apache.commons.lang.except ...

  5. JZOJ.5275【NOIP2017模拟8.14】水管

    Description

  6. CKEDITOR 3.4.2中 按钮事件中 动态改变图标和title 获取按钮

    this.uiItems[0].className="cke_button_hui_position_type";this.uiItems[0].title="zhang ...

  7. mybatis循环map

    一.循环key <foreach collection="map.keys" item="key" separator="and"&g ...

  8. Fluent Ribbon 第八步 其他控件

    前七节将Ribbon的功能大致介绍了一番,本节来介绍一些特殊控件的使用 DropDownButton控件 当前控件是显示下拉功能的基本组件,其配合Gallery能实现诸多特殊功能,代码如下所示 < ...

  9. 4.Data Types in the mongo Shell-官方文档摘录

    总结: 1.MongoDB 的BSON格式支持额外的数据类型 2 Date 对象内部存储64位字节存整数,存储使用NumberLong()这个类来存,使用NumberInt()存32位整数,128位十 ...

  10. 配置 Docker 镜像下载的本地 mirror 服务

    Docker registry 工具如今已经非常好的支持了 mirror 功能,使用它能够配置一个本地的 mirror 服务.将 pull 过的镜像 cache 在本地.这样其他主机再次 pull 的 ...