Programming Abstractions in C阅读笔记:p293-p302
《Programming Abstractions in C》学习第73天,p293-p302总结,总计10页。
一、技术总结
1.时间复杂度
(1)quadratic time(二次时间)
p293, Algorithms like selection sort that exhibit O(N^2) performance are said to run in quadratic time。
2.线性查找(linear search)
p293, Because the for loop in the implementation executes n time, you expect the performance of LinearSearch——as its name implies——to be O(N)。时间复杂度为O(N)的查找称为线性查找。
3.归并排序(merge sort)
书中并为对归并排序做严格的定义。p298, The merge operation, combined with recursive decomposition, gives rise to a new sorting algorithm called merge sort, which you can implement in straightforward way. The basic idea of the algorithm can be outlined as follows:
- Check to see if the array is empty or has only one element. If so, it must alread be sorted, and the function can return without doing any work. This condition defines the simple case for the recursion.
- Divide the array into two new subarrays, each of which is half the size of the original.
- Sort each of the subarrasy recursively.
- Merge the two subarrays back into the original one.
/*
* 伪代码
*/
static void Merge(int array[], int arr1[], int n1, int arr2[], int n2);
static int *CopySubArray(int array[], int start, int n);
void SortIntegerArray(int array[], int n);
/*
* Function: SortIntegerArray
* Usage: SortIntegerArray(array, n);
* ----------------------------------
* This function sorts the first n elements of array into
* increasing numerical order using the merge sort algorithm,
* which requires (1) dividing the array into two halves,
* (2) sorting each half, and (3) merging the halves together.
*/
void SortIntegerArray(int array[], int n) {
int n1, n2, *arr1, *arr2;
if (n <= 1) {
return;
}
n1 = n / 2;
n2 = n - n1;
arr1 = CopySubArray(array, 0, n1);
arr2 = CopySubArray(array, 0, n2);
SortIntegerArray(arr1, n1);
SortIntegerArray(arr1, n2);
Merge(array, arr1, n1, arr2, n2);
FreeBlock(arr1);
FreeBlock(arr2);
}
/*
* Function: Merge
* Usage: Merge(array, arr1, n1, arr2, n2);
* ----------------------------------------
* This function merges two sorted arrays (arr1 and arr2) into a
* single output array. Because the input arrays are sorted, the
* implementation can always select the first unused element in
* one of the input arrays to fill the next position in array.
*/
static void Merge(int array[], int arr1[], int n1, int arr2[], int n2) {
int p, p1, p2;
p = p1 = p2 = 0;
while (p1 < n1 && p2 < n2) {
if (arr1[p1] < arr2[p2]) {
array[p++] = arr1[p1++];
} else {
array[p++] = arr2[p2++];
}
}
while (p1 < n1) {
array[p++] = arr1[p1++];
}
while (p2 < n2) {
array[p++] = arr2[p2++];
}
}
/*
* Function: CopySubArray
* Usage: CopySubArray(array, arr1, n1, arr2, n2);
* -----------------------------------------------
* This function makes a copy of a subset of an integer array
* and returns a pointer to a new dynamic array containing the
* new elements. The array begins at the indicated start
* position in the original array and continues for n elemnts.
*/
static int *CopySubArray(int array[], int start, int n) {
int i, *result;
result = NewArray(n, int);
for (i = 0; i < n; i++) {
result[i] = array[start + i];
}
return result;
}
二、英语总结
1.quadratic是什么意思?
答:In mathematics by 1660s;the algebraic quadratic euqation(二次方程, 1680s) are so called because they involve the square(x^2) and no higher power of x。这里要注意quarter是四分之一,但是quadratic是二次(x^2)的意思。
2.sophistication是什么意思?
答:
(1)sophist > sophiticate > sophistication。
(2)sophist: one who makes use of fallacious arguments(诡辩者)。
(3)sophistication: u. the quality of being sophisticated(老练, 复杂度)。
p293, The problem, howerver is that average-case analysis is much more difficult to carry out and typically requires considerable mathematical sophistication。这里比较重要的一点是虽然这里用的是名词sophistication,但是因为翻译的时候需要转一下,mathematical sophistication(复杂的数学知识)。
3.average用法总结
答:
(1)vt. to reach a particular amount as an average。主语可以是物也可以是人。翻译的时候需要灵活转变。
主语是物:Inquires to our office average 1000 calls a month.
主语是人:p294, From a practical point of view, it is often useful to consider how well an algorithm performs if you average its behavior over all possible sets of input data
三、其它
本书中作者讲解归并排序(merge sort)和其它书还是有些不同的,从选择排序算法展开,从而引出归并排序算法,可以和其它书进行对比阅读。
四、参考资料
1. 编程
(1)Eric S.Roberts,《Programming Abstractions in C》:https://book.douban.com/subject/2003414
2. 英语
(1)Etymology Dictionary:https://www.etymonline.com
(2) Cambridage Dictionary:https://dictionary.cambridge.org
欢迎搜索及关注:编程人(a_codists)
Programming Abstractions in C阅读笔记:p293-p302的更多相关文章
- Mongodb Manual阅读笔记:CH3 数据模型(Data Models)
3数据模型(Data Models) Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作Mongodb Manual阅读笔记:CH3 数据模型(Data Models)Mon ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十三章:角色动画
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十三章:角色动画 学习目标 熟悉蒙皮动画的术语: 学习网格层级变换 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十一章:模板测试
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十一章:模板测试 代码工程地址: https://github.co ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制 代码工程地址: https://gi ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第四章:Direct 3D初始化
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第四章:Direct 3D初始化 学习目标 对Direct 3D编程在 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数 学习目标: 理解矩阵和与它相关的运算: 理解矩阵的乘 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第一章:向量代数
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第一章:向量代数 学习目标: 学习如何使用几何学和数字描述 Vecto ...
- 阅读笔记 1 火球 UML大战需求分析
伴随着七天国庆的结束,紧张的学习生活也开始了,首先声明,阅读笔记随着我不断地阅读进度会慢慢更新,而不是一次性的写完,所以会重复的编辑.对于我选的这本 <火球 UML大战需求分析>,首先 ...
- [阅读笔记]Software optimization resources
http://www.agner.org/optimize/#manuals 阅读笔记Optimizing software in C++ 7. The efficiency of differe ...
- 《uml大战需求分析》阅读笔记05
<uml大战需求分析>阅读笔记05 这次我主要阅读了这本书的第九十章,通过看这章的知识了解了不少的知识开发某系统的重要前提是:这个系统有谁在用?这些人通过这个系统能做什么事? 一般搞清楚这 ...
随机推荐
- [转帖]goproxy的设置
goproxy.io 是全球最早的 Go modules 镜像代理服务之一 [大陆地区建议使用 proxy.golang.com.cn],采用 CDN 加速服务为开发者提供依赖下载, 该服务由一批热爱 ...
- [转帖]Prometheus监控系统存储容量优化攻略,让你的数据安心保存!
云原生监控领域不可撼动,Prometheus 是不是就没缺点?显然不是. 一个软件如果什么问题都想解决,就会导致什么问题都解决不好.所以Prometheus 也存在不足,广受诟病的问题就是 单机存储不 ...
- Linux 通过命令方式反编译jar包的方法
第一步: 复制jar包到指定路径. find . -iname "*.jar" -exec scp {} /root/bf/ \; 第二步: 解压缩jar包解压缩出来class文件 ...
- SAP PO7.5 有关https 接口body编码格式 application/x-www-form-urlencoded
近期项目中,在PO中做接口 遇到OAUTH2.0认证方式,token获取过程中编码格式为 "application/x-www-form-urlencoded" 实现过程错误记录: ...
- elementui 的tabs组件出现蓝色边框问题
elementui 的tabs组件出现蓝色边框问题 /deep/ .el-tabs__item:focus.is-active.is-focus:not(:active) { -webkit-box- ...
- http 中使用 gzip 输出内容时,如何预先压缩前一半页面?
作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢! cnblogs博客 zhihu Github 公众号:一本正经的瞎扯 背景是这样:要输出一个很大的动态页面,不开 gzip 压缩 ...
- 【JS 逆向百例】吾爱破解2022春节解题领红包之番外篇 Web 中级题解
关注微信公众号:K哥爬虫,持续分享爬虫进阶.JS/安卓逆向等技术干货! 逆向目标 本次逆向的目标来源于吾爱破解 2022 春节解题领红包之番外篇 Web 中级题,吾爱破解每年都会有派送红包活动(送吾爱 ...
- Go中sync.map使用小结
sync.map 前言 深入了解下 查看下具体的实现 Load Store Delete LoadOrStore 总结 流程图片 参考 sync.map 前言 Go中的map不是并发安全的,在Go1. ...
- 1.13 导出表劫持ShellCode加载
在Windows操作系统中,动态链接库DLL是一种可重用的代码库,它允许多个程序共享同一份代码,从而节省系统资源.在程序运行时,如果需要使用某个库中的函数或变量,就会通过链接库来实现.而在Window ...
- C++ Boost库 操作字符串与正则
字符串的查找与替换一直是C++的若是,运用Boost这个准标准库,将可以很好的弥补C++的不足,使针对字符串的操作更加容易. 字符串格式转换: #include <iostream> #i ...