Skip to Content
算法技术手册(原书第2 版)
book

算法技术手册(原书第2 版)

by George T.Heineman, Gary Pollice, Stanley Selkow
August 2017
Intermediate to advanced
360 pages
8h 35m
Chinese
China Machine Press
Content preview from 算法技术手册(原书第2 版)
算法的数学原理
29
算法的
数学原理
其他的加法实现应该会有不同的常数,但是它们的总体表现仍然呈线性。这个结果让那
些认为整数算术是常数操作的程序员大吃一惊。不过,当整数的位数固定(例如
16
或者
64
位)时,我们可以认为加法是常数时间。
在考虑算法之间的差异时,了解算法的增长率比常数
c
更为重要。看似无关紧要的差
异可能就会导致不同的性能。加法算法的
plus
实现试图通过消除取模计算(
%
)来提
升算法效率。尽管如此,在
plus
add
采用
-O3
优化时,
add
还是要比
plus
实现快
30%
。当然,这并不是说可以忽略掉常数
c
的值。如果做大量
加法
,那么
c
的一点点
小变动都会对程序的性能产生很大的影响。
2.4.5 线性对数算法的性能
性能指标很好地描述了同类算法的共同行为。为了更好地阐述算法在实践中的行为,
我们定义了一个函数
t
(
n
)
,用于表示算法解决样本规模为
n
的问题所需要的时间。分治
法是解决问题的一个高效方法,它将规模为
n
的问题划分成(大致相等的)两个规模为
n/
2
的子问题,并通过递归解决问题。这些子问题会通过线性时间
方式合并在一起来解
决原先规模为
n
的问题。使用数学表达式可以表示为:
t
(
n
) =
2
*
t
(
n/2
) +
c
*
n
也就是说,
t
(
n
)
包括了解决两个子问题和归并结果的
费用,其中归并结果的费用不超过
线性时间(即
c
*
n
)。在等式的右边,
t
(
n
/
2
)
是解决规模为
n/
2
的问题的时间,按此逻辑
推理,
t
(
n
/2)
可以表示为:
t
(
n
/2) = 2
*
t
(
n/
4) +
c
*
n
/2
所以最初的等式可以写为: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

Aurélien Géron
Go语言编程

Go语言编程

威廉·肯尼迪

Publisher Resources

ISBN: 9787111562221