算法导论24-26、34-35章

单源最短路

问题描述:
给定带权重的有向图G=(V,E)和权重函数w,能够将每条边映射到实数值得权重上。
给定一个源点,希望求出它到所有节点的最小权重路径。

定义路径的权重
该路径上所有边的权重之和
在这里插入图片描述

定义最短路径权重
在这里插入图片描述

最短路径问题具有最优子结构
即最短路径的子路径也是最短路径
本质上还是反证法的思想
在这里插入图片描述
负权重的边
1.Bellman-Ford算法允许图中有负权环;并且能够检测负权回路的存在
2.Dijkstra算法要求边非负。

环路
1、最短路径不能包含权重为负值的环——否则最短路径可能会导致-∞
2、最短路径不能包含权重为正值的环——如果包含这样的环,那么我们删掉这个环,可以得到一个更小的最短路径
因此,最短路径中没有环路,是简单路径。
因此,一条最短路径最多包含V个结点,|V|-1条边。

展示最短路
需要为每个结点维持一个前驱结点Π,Π=NIL或为另一个结点。
由此,我们可以定义出 V π 和 E π V_\pi和E_\pi VπEπ:
在这里插入图片描述
G π G_\pi Gπ是一棵最短路径树,包含了从源节点s到每个可以到的顶点的一条最短路径。
最短路径不一定是唯一的,最短路径树也不一定是唯一的。

松弛操作:
为每个结点维持另一个属性d,用来记录从s到该结点的最短路径权重的上界,称d为最短路径估计。
松弛:唯一导致最短路径估计d和前驱节点 π \pi π发生变化的操作
在这里插入图片描述
Dijkstra:对每条边仅松弛
Bellman-Ford:每条边松弛|V|-1次

初始化
为所有结点初始化d和 π \pi π两个属性:
在这里插入图片描述

一些性质
在这里插入图片描述



Bellman-Ford算法

允许权重为负值的边
通过对边进行松弛操作降低所有顶点的最短路径估计d,并更新 π \pi π值,直到d=最短路径权重。
除此之外,算法会返回一个布尔值来表明图中是否存在负权环。

BELLMAN-FORD(G,w,s)
	INITIALIZE-SINGLE-SOURCE(G,s)
	for i = 1 to G.|V|-1	//因此最短路径的长度至多为|V|-1
		for each edge (u,v) ∈ G.E
			RELAX(u,v,w)
	for each edge(u,v) ∈ G.E	//检测负权环
		if v.d > u.d + w(u,v)
			return FALSE
	return TRUE

T ( n ) = Θ ( V ) + Θ ( E ( V − 1 ) ) + O ( E ) = O ( V ⋅ E ) T(n)=\Theta(V)+\Theta(E(V-1))+O(E)=O(V·E) T(n)=Θ(V)+Θ(E(V1))+O(E)=O(VE)



DAG算法

先对有向无环图进行拓扑排序,确定每个结点之间的一个线性次序。如果有u到v的一条边,那u的次序在v前面。
我们只需要按照拓扑排序对结点进行一遍处理,每次对一个节点进行处理时,对该结点发出的所有边进行松弛操作

DAG-SHORTEST-PATHS(G,w,s)
1	topologically sort the vertices of G
2	INITIALIZE-SINGLE-SOURCE(G,s)
3	for each vertex u,taken in topologically sorted order
4		for each vertex v that u adjacent to	//可以建立一个邻接数组,adj[u]
5			RELAX(u,v,w)

时间复杂度:
在这里插入图片描述



Dijkstra算法

要求所有边权重非负。
每次选择一个“最短”的路径——贪心算法

DIJKSTRA(G,w,s)
	INITIALIZE-SINGLE-SOURCE(G,s)	//初始化
	S = 空集
	Q = G.V		//始终满足Q=V-S
	While Q != 空集
		u = EXTRACT-MIN(Q)	//u是未加入结点中最小最短路估计
		S = S ∪ {u}
		//如果经过u的路径使s到v更短,则更新v的属性
		for each vertex v ∈ G.adj[u]
			RELAX(u,v,w)

Dijkstra算法的实现依赖于最小优先队列
1.利用编号结点来维持最小优先队列:EXTRACT-MIN需要 O ( V ) O(V) O(V),搜索整个数组, T ( n ) = O ( V 2 + E ) = O ( V 2 ) T(n)=O(V^2+E) = O(V^2) T(n)=O(V2+E)=O(V2)
2.使用斐波那契堆实现最小优先队列:
EXTRACT-MIN需要 O ( l g V ) O(lgV) O(lgV) T ( n ) = O ( V l g V + E ) T(n)=O(VlgV+E) T(n)=O(VlgV+E)



所有结点最短路

不再给出源点,需要求所有结点对之间的最短路径,实际上就是|V|次单源最短路,但这样做效率很低。

为了求出问题,不仅需要计算最短路权重,还需要计算出前驱结点矩阵 Π = ( π i j ) \Pi=(\pi_{ij}) Π=(πij) π i j \pi_{ij} πij在i=j或不存在i到j路径时为NIL,否则给出的是从i到j的最短路上j的前驱结点。

同样,我们可以定义一个最短路径树 G π , i G_{\pi,i} Gπ,i,只是这里多了一个参数–我们需要给出根节点i:

PRINT-ALL-PAIRS-SHORTEST-PATH(Π,i,j)
	if i == j
		print i
	elseif Π_ij == NIL
		print "no path from i to j exists"
	else PRINT-ALL-PAIRS-SHORTEST-PATH(Π,i,Π_ij)
	print j

下面给出三种解决方法
1、基于矩阵乘法的动态规划算法—— Θ ( V 3 l g V ) \Theta(V^3lgV) Θ(V3lgV)
2、Floyd-Warshll算法(动态规划)—— Θ ( V 3 ) \Theta(V^3) Θ(V3)
3、Johnson算法—— O ( V 2 l g V + V E ) O(V^2lgV+VE) O(V2lgV+VE)

基于矩阵乘法的动态规划

定义 l i j ( m ) l_{ij}^{(m)} lij(m)表示从i到j至多包含m条边的任意路径的最小权重
m = 0 m=0 m=0,在这里插入图片描述
m ≥ 1 m\ge1 m1在这里插入图片描述
我们考虑图中不含负权环,而最短路最多n-1条边,因此 最小路径权重 = l i j ( n − 1 ) = l i j ( n ) = l i j ( n + 1 ) = . . . 最小路径权重=l_{ij}^{(n-1)}=l_{ij}^{(n)}=l_{ij}^{(n+1)}=... 最小路径权重=lij(n1)=lij(n)=lij(n+1)=...

输入矩阵 W i , j = ( w i j ) W_{i,j}=(w_{ij}) Wi,j=(wij),且 L ( 1 ) = W L^{(1)}=W L(1)=W
通过对最短路径一条边一条边的扩展来计算最短路权重。

EXTENDED-SHORTEST-PATHS(L,W)
	n = L.rows
	let L' = (l_ij') be a new n*n matrix
	for i = 1 to n
		for j = 1 to no
			l_ij' =for k =1 to n
				l_ij' = min(l_ij',l_k+w_kj)
	return L'

返回矩阵L’=(l_ij’)
T ( n ) = Θ ( n 3 ) T(n)=\Theta(n^3) T(n)=Θ(n3)

SLOW-ALL-PAIRS-SHORTEST-PATHS(W)
	n = W.rows
	L(1) = W
	for m = 2 to n-1
		Let L(m) be a new n*n  matrix
		L(m) =  EXTENDED-SHOERTEST-PATH(L(m-1),W)
	return L(n-1)

这样算 T ( n ) = Θ ( n 4 ) T(n)=\Theta(n^4) T(n)=Θ(n4)
我们考虑改进算法
由我们刚刚推导出的 最小路径权重 = l i j ( n − 1 ) = l i j ( n ) = l i j ( n + 1 ) = . . . 最小路径权重=l_{ij}^{(n-1)}=l_{ij}^{(n)}=l_{ij}^{(n+1)}=... 最小路径权重=lij(n1)=lij(n)=lij(n+1)=...,我们可以采用重复平方技术来减小时间复杂度:
在这里插入图片描述

FASTER-ALL-PAIRS-SHORTEST-PATHS(W)
	n = W.rows
	L(1) = W
	m = 1
	while m <= n
		Let L(2m) be a new n*n matrix
		L(2m) = EXTENDED-SHORTEST-PATHS(L(m),L(m))
	return L(m)

最后的结果 L ( m ) = L ( n − 1 ) L^{(m)} = L^{(n-1)} L(m)=L(n1)
一共计算了lg(n-1)取上整个矩阵,每个矩阵时间为 Θ ( n 3 ) \Theta(n^3) Θ(n3),因此 T ( n ) = Θ ( n 3 l g n ) T(n)=\Theta(n^3lgn) T(n)=Θ(n3lgn)


Floyd-Warshall算法

允许负权重的边存在。
动态规划算法。

d i j ( k ) d_{ij}^{(k)} dij(k)为从结点i到j的所有中间结点全部取自{1,2,…,k}的一条最短路的权重。
在这里插入图片描述

FLOYD-WARSHALL(W)
	n = W.rows
	D(0) = W
	for k = 1 to n
		let D(k) = (d_ji^k)be a new n*n matrix
		for i = 1 to n
			for j = 1 to n
				d_ij^k = min(d_ij^(k-1),d_ik^(k-1)+d_kj^(k-1))
	return D(n)

三层循环 T ( n ) = Θ ( n 3 ) T(n) = \Theta(n^3) T(n)=Θ(n3)

这里只返回了权重矩阵,仍需构建一条最短路,需要构建前驱矩阵
1、先计算权重矩阵D,从D构造前驱矩阵 Π \Pi Π,再用PRINT-ALL-PAIRS-SHORTEST-PATH打印最短路径, T ( n ) = O ( n 3 ) T(n)=O(n^3) T(n)=O(n3)
2、计算 D ( k ) D^{(k)} D(k)的同时计算前驱矩阵 Π \Pi Π,定义 Π = Π ( n ) 且 Π i j ( k ) \Pi=\Pi^{(n)}且\Pi_{ij}^{(k)} Π=Π(n)Πij(k)为从i到j的一条所有中间结点取自{1,2,…,k}的最短路径上j的前驱节点
在这里插入图片描述
传递闭包
定义:传递闭包为图 G ∗ = ( V , E ∗ ) G^*=(V,E^*) G=(V,E),其中 E ∗ = i , j :如果图 G 中有一条 i 到 j 的路径 E^*={i,j:如果图G中有一条i到j的路径} E=ij:如果图G中有一条ij的路径

我们定义 t i j ( k ) = 1 t_{ij}^{(k)}=1 tij(k)=1代表图G中存在一条从i到j的路径,其中间结点均属于{1,2,…,k}中,否则 = 0 =0 =0.那么传递闭包 G ∗ = ( V , E ∗ ) G^*=(V,E^*) G=(V,E):将边(i,j)置于 E ∗ 中    ⟺    t i j ( j ) = 1 E^*中\iff t_{ij}^{(j)}=1 Etij(j)=1
在这里插入图片描述

TRANSITIVE-CLOSURE(G)
	n = |G.V|
	let T(0) = (t_ij^0) be a new n*n matrix
	for i = 1 to n
		for j = 1 to n
			if i==j or (i,j)∈E
				t_ij^0 = 1
			else t_ij^0 = 0
	for k = 1 to n
		let T(K) = (t_ij^k) be a new n*n matrix
		for i = 1 to n
			for j = 1 to n
				t_ij^k = t_ij^(k-1) ∨ (t_ik^(k-1) ∧ t_kj^(k-1)return T(n)

T ( n ) = Θ ( n 3 ) T(n) = \Theta(n^3) T(n)=Θ(n3)
最后得到的结果实际上是个可达矩阵,因为得到的路径它中间能够包含所有结点。若第i行第j列为1,就代表着存在着从i至j的一条路径。

稀疏图Johnson算法

在这个算法中使用到了Dijkstra算法和Bellman-Ford算法:
1、它会返回包含所有结点对的最短路径权重的矩阵;
2、并报告输入图中是否存在负权环路

Johnson算法为边重新赋予权重
如果图G中所有边权重非负,可以通过对每个结点运行一次Dijkstra算法解决问题;若使用斐波那契堆最小优先队列, T ( n ) = O ( V 2 l g V + V E ) T(n)=O(V^2lgV+VE) T(n)=O(V2lgV+VE);
如果G中有负权重边,但没有负权环路,那么只要计算出一组新的非负权重值,然后使用Dijkstra算法。新赋予的权重 u ^ \hat{u} u^必须满足两个性质:
1、不改变最短路径的性质
2、新权重非负
在这里插入图片描述

JOHNSON(G,w)

在这里插入图片描述

在这里插入图片描述
若使用斐波那契堆实现Dijkstra中的最小优先队列,算法 T ( n ) = O ( V 2 l g V + V E ) T(n)=O(V^2lgV+VE) T(n)=O(V2lgV+VE)
若使用二叉最小堆, T ( n ) = O ( V E l g V ) T(n)=O(VElgV) T(n)=O(VElgV)



最大流

流网络G=(V,E)是一个有向图,每条边有一个非负容量值 c ( u , v ) ≥ 0 c(u,v)\ge0 c(u,v)0,并且若E中有边(u,v),则不含其反向边(v,u).
流网络中有一个源节点s,汇点t。若对于每个结点来说,都有一条从s经过v到t的路径,那我们说流网络是流通的。
除s外,每个结点都至少有一条进入边,因此 ∣ E ∣ ≥ ∣ V ∣ − 1 |E|\ge |V|-1 EV1

流:满足性质:容量限制 & 流量守恒

容量限制:对所有结点v,要求流的大小不超过容量大小
流量守恒:对所有除s、t之外的结点,要求从结点流出的总流量=流入结点的总流量和

流的大小
从源点流出的总流量-流入源点的总流量
在这里插入图片描述

Fold-Fulkerson算法

关键思想:残存网络、增广路径、切割

构建残存网络,寻找一条增广路径,修改流的值,在残存图中添加反向边;循环此过程直到找不到增广路径为止。

总的来看,每次迭代都会增加流的值,但对于G中的一条特定来说,其流量可能增加也可能减少,这是因为对某些边缩减是有必要的,这可能会让更多的流从源点发送到汇点。

这种算法能够获得一个最大流

一、残存网络

残存网络:
定义一条边可以允许额外流量=该边容量-该边上的流量,称之为残存容量
在这里插入图片描述
残存网络 G f = ( V , E f ) , E f = ( u , v ) ∈ V ∗ V : c f ( u , v ) > 0 G_f=(V,E_f),E^f ={ (u,v)∈V*V:c_f(u,v)>0 } Gf=(V,Ef),Ef=(u,v)VV:cf(u,v)>0,也就是说残存网络中的每条边或残存边都必须允许大于0的流量通过; E f E_f Ef中的边要么是E中所有边,要么是其反向边,因此有 ∣ E f ∣ ≤ 2 ∣ E ∣ |E_f|\le 2|E| Ef2∣E

需要厘清,残存网络并不是流网络,因为他不满足流网络的定义——他可能包含边(u,v)及其反向边(v,u)。
除此之外,它具有和流网络同样的性质。

二、增广路径

增广路径:
残存网络中一条从源点s到汇点t的简单路径。
每条这样的路径它的流量值决定于路径上所有边的最小残存容量。在这里插入图片描述

三、切割

流网络中的一个切割(S,T)将V划分为S和T两个集合,T=V-S,且源点s∈S,汇点t∈T。

若f是一个流,则定义横跨切割(S,T)的净流量f为:从集合S中流出的总流量-流入集合S的总流量在这里插入图片描述
切割(S,T)的容量是从集合S到集合T所有路径的总容量在这里插入图片描述

我们只关注最小切割——整个网络中容量最小的切割

对于给定的流f,横跨任何切割的净流量都相同,都等于|f|

流网络中,任意流f的值都不能超过任意切割的容量

最大流最小割定理
在这里插入图片描述

FOLD-FULKERSON-METHOD(G,s,t)
	for each edge(u,v)∈G.E
		(u,v).f = 0	//初始化流f=0
	while there exists a path p from s to t in the residual network Gf
		c_f(p) = min {c_f(u,v):(u,v) is in p}	//找到路径p的瓶颈值
		for each edge (u,v) in p
			//对流进行更新,若残存边是G中边,则加流量,否则减流量
			if (u,v)E
				(u,v).f = (u,v).f + c_f(p)
			else (v,u).f = (v,u).f - c_f(p)

运行时间取决于如何寻找增广路径
如果使用深度优先/广度优先搜索,在残存网络中找到一条路径的时间应是 O ( V + E ′ ) = O ( E ) O(V+E') = O(E) O(V+E)=O(E),因此while每一遍执行所需O(E),而while最多循环次数是 ∣ f ∗ ∣ |f^*| f次,所以 T ( n ) = O ( E ∣ f ∗ ∣ ) T(n)=O(E|f^*|) T(n=O(Ef)



Edmonds-Karp算法

改变FOLD-FULKERSON算法,使要找的增广路径为从s到t的最短路径,其中每条边的权重为单位距离。
这样,算法时间为 O ( V E 2 ) O(VE^2) O(VE2)

最大二分匹配

使用FOLD-FULKERSON 算法能在 O ( V E ) O(VE) O(VE)时间内解决图G=(V,E)的最大二分匹配问题。

二分图:在这里插入图片描述
构建一个流网络,其中流对应匹配。
我们设源节点s和汇点t是不属于结点集V的新节点,并且V’=V ∪ {s,t}
在这里插入图片描述
|M|——二分图中能匹配的最多结点对个数
利用FOLD算法在G’中找到一条最大流f,那么G中就存在一个匹配M,满足|M| = |f|



P与NP

基础定义:P、NP、NPC

下面主要是一些常见的NPC问题。
电路可满足性问题——第一个证明的NPC问题。
在这里插入图片描述

团问题CLIQUE

寻找图中规模最大的团的最优化问题。
实际上就是找图G中最大的完全子图。

证明团问题是NPC问题:证明 3 − C N F − S A T ≤ p C L I Q U E 3-CNF-SAT\le_p CLIQUE 3CNFSATpCLIQUE

顶点覆盖问题VERTEX COVER

给出一个图G,找到一个最小的顶点集合,使其能够覆盖G中每条边

证明顶点覆盖问题是NPC问题:证明 C L I Q U E ≤ p V E R T E X − C O V E R CLIQUE\le_p VERTEX-COVER CLIQUEpVERTEXCOVER

哈密顿回路问题HAM-CYCLE

给出一个图G,找出一条回路,使其能够恰经过所有顶点仅1次。

证明哈密顿回路是NPC问题:证明 V E R T E X − C O V E R T ≤ p H A M − C Y C L E VERTEX-COVERT\le_p HAM-CYCLE VERTEXCOVERTpHAMCYCLE

旅行商问题TSP

经过哈密顿回路,恰好访问每个城市一次,并回到出发城市。
除此之外,要求费用最小——每条路的权重之和

证明旅行商问题是NPC问题:证明 H A M − C Y C L E ≤ p T S P HAM-CYCLE\le_p TSP HAMCYCLEpTSP

子集和问题SUBSET-SUM

给出一个有限正整数集合S和一个整数目标t>0,找到一个字集合,使其所有元素和恰好为t。

证明子集和问题是NPC问题:证明 3 − C N F − S A T ≤ p S U B S E T − S U M 3-CNF-SAT\le_p SUBSET-SUM 3CNFSATpSUBSETSUM

所有证明过程在此处省略。



近似算法

近似算法:返回近似最优解的算法

近似比:

  • 最大化问题:满足 0 < C ≤ C ∗ 0\lt C \leq C^* 0<CC,比值 C ∗ / C C^*/C C/C表示最优解代价大于近似解代价的倍数。
  • 最小化问题:满足 0 < C ∗ ≤ C 0\lt C^* \leq C 0<CC,比值 C / C ∗ C/C^* C/C表示近似解代价大于最优解代价的倍数。
  • 算法的近似比不会小于1
  • 一个1近似算法产生的解就是最优解;而一个近似比较大的近似算法可能会返回和最优解差很多的解

一些NPC问题可以采用特定的多项式时间近似算法求解,通过消耗更多的计算时间来得到不断缩小的近似比;另一些问题,在已知的最佳多项式时间近似算法中,近似比是输入规模n的函数,随着n的变化而变化。

  • 一个最优化问题的近似模式approximation scheme就是近似算法:
    • 输入除了问题的实例外,还有一个值 ϵ > 0 \epsilon > 0 ϵ>0,使得对于任何固定 ϵ \epsilon ϵ,该模式是一个 ( 1 + ϵ ) (1+\epsilon) (1+ϵ)近似算法。

    • 对一个近似模式来说,如果对任何固定的 ϵ > 0 \epsilon > 0 ϵ>0,该模式都以输入实例规模n的多项式时间运行,则称此模式为多项式时间近似模式

    • 随着 ϵ \epsilon ϵ的减小,多项式时间近似模式的运行时间可能会迅速增长在这里插入图片描述

    • 完全多项式时间近似模式在这里插入图片描述
      下面给出一些NPC问题的近似算法。

顶点覆盖问题

规模不超过 最优顶点覆盖规模2倍的顶点覆盖

在这里插入图片描述
例:
在这里插入图片描述
邻接表来表示E,算法的运行时间为 O ( V + E ) O(V+E) O(V+E)

旅行商问题

满足三角不等式:
两地之间直接到达的代价最小
在这里插入图片描述
我们考虑满足三角不等式的旅行商问题,近似算法代价不超过最优的2

在这里插入图片描述
例:
在这里插入图片描述

一般旅行商问题,即没有满足三角不等式的假设,那么问题就无法在多项式时间内找到一个好的近似算法,除非P=NP

集合覆盖问题set-cover

给出一个有穷集X,和它的一个子集族,每个元素至少在一个子集中,我们希望找到一个最小数量的子集集合,使其能覆盖X中所有元素。

贪心近似算法:
在这里插入图片描述
在这里插入图片描述
近似比是 l n ∣ X ∣ + 1 ln|X|+1 lnX+1

带权顶点覆盖问题

在顶点覆盖问题中,每个顶点都具有一个正权值,希望找出一个具有最小权的顶点覆盖

利用线性规划松弛,构造近似解
在这里插入图片描述
该算法是一个近似比为2的近似算法

子集和问题

指数时间的近似算法
在这里插入图片描述
完全多项式时间近似模式
在这里插入图片描述
在这里插入图片描述

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
在有关算法的书中,有一些叙述非常严谨,但不够全面;另一些涉及了大量的题材,但又缺乏严谨性。本书将严谨性和全面性融为一体,深入讨论各类算法,并着力使这些算法的设计和分析能为各个层次的读者接受。全书各自成体系,可以作为独立的学习单元;算法以英语和伪代码的形式描述,具备初步程序设计经验的人就能看懂;说明和解释力求浅显易懂,不失深度和数学严谨性。 --------------------------------------------------------------- 目录 Introduction to Algorithms, Third Edition 出版者的话 译者序 前言 第一部分 基础知识 第1 算法在计算中的作用  1.1 算法  1.2 作为一种技术的算法  思考题  本注记 第2 算法基础  2.1 插入排序  2.2 分析算法  2.3 设计算法   2.3.1 分治法   2.3.2 分析分治算法  思考题  本注记 第3 函数的增长  3.1 渐近记号  3.2 标准记号与常用函数  思考题  本注记 第4 分治策略  4.1 最大子数组问题  4.2 矩阵乘法的Strassen算法  4.3 用代入法求解递归式  4.4 用递归树方法求解递归式  4.5 用主方法求解递归式  4.6 证明主定理   4.6.1 对b的幂证明主定理   4.6.2 向下取整和向上取整  思考题  本注记 第5 概率分析和随机算法  5.1 雇用问题  5.2 指示器随机变量  5.3 随机算法  ?5.4 概率分析和指示器随机变量的进一步使用   5.4.1 生日悖论   5.4.2 球与箱子   5.4.3 特征序列   5.4.4 在线雇用问题  思考题  本注记 第二部分 排序和顺序统计量 第6 堆排序  6.1 堆  6.2 维护堆的性质  6.3 建堆  6.4 堆排序算法  6.5 优先队列  思考题  本注记 第7 快速排序  7.1 快速排序的描述  7.2 快速排序的性能  7.3 快速排序的随机化版本  7.4 快速排序分析   7.4.1 最坏情况分析   7.4.2 期望运行时间  思考题  本注记 第8 线性时间排序  8.1 排序算法的下界  8.2 计数排序  8.3 基数排序  8.4 桶排序  思考题  本注记 第9 中位数和顺序统计量  9.1 最小值和最大值  9.2 期望为线性时间的选择算法  9.3 最坏情况为线性时间的选择算法  思考题  本注记 第三部分 数据结构 第10 基本数据结构  10.1 栈和队列  10.2 链表  10.3 指针和对象的实现  10.4 有根树的表示  思考题  本注记 第11 散列表  11.1 直接寻址表  11.2 散列表  11.3 散列函数   11.3.1 除法散列法   11.3.2 乘法散列法   11.3.3 全域散列法  11.4 开放寻址法  11.5 完全散列  思考题  本注记 第12 二叉搜索树  12.1 什么是二叉搜索树  12.2 查询二叉搜索树  12.3 插入和删除  12.4 随机构建二叉搜索树  思考题  本注记 第13 红黑树  13.1 红黑树的性质  13.2 旋转  13.3 插入  13.4 删除  思考题  本注记 第14 数据结构的扩张  14.1 动态顺序统计  14.2 如何扩张数据结构  14.3 区间树  思考题  本注记 第四部分 高级设计和分析技术 第15 动态规划  15.1 钢条切割  15.2 矩阵链乘法  15.3 动态规划原理  15.4 最长公共子序列  15.5 最优二叉搜索树  思考题  本注记 第16 贪心算法  16.1 活动选择问题  16.2 贪心算法原理  16.3 赫夫曼编码  16.4 拟阵和贪心算法  16.5 用拟阵求解任务调度问题  思考题  本注记 第17 摊还分析  17.1 聚合分析  17.2 核算法  17.3 势能法  17.4 动态表   17.4.1 表扩张   17.4.2 表扩张和收缩  思考题  本注记 第五部分 高级数据结构 第18 B树  18.1 B树的定义  18.2 B树上的基本操作  18.3 从B树中删除关键字  思考题  本注记 第19 斐波那契堆  19.1 斐波那契堆结构  19.2 可合并堆操作  19.3 关键字减值和删除一个结点  19.4 最大度数的界  思考题  本注记 第20 van Emde Boas树  20.1 基本方法  20.2 递归结构   20.2.1 原型van Emde Boas结构   20.2.2 原型van Emde Boas结构上的操作  20.3 van Emde Boas树及其操作   20.3.1 van Emde Boas树   20.3.2 van Emde Boas树的操作  思考题  本注记 第21 用于不相交集合的数据结构  21.1 不相交集合的操作  21.2 不相交集合的链表表示  21.3 不相交集合森林  *21.4 带路径压缩的按秩合并的分析  思考题  本注记 第六部分 图算法 第22 基本的图算法  22.1 图的表示  22.2 广度优先搜索  22.3 深度优先搜索  22.4 拓扑排序  22.5 强连通分量  思考题  本注记 第23 最小生成树  23.1 最小生成树的形成  23.2 Kruskal算法和Prim算法  思考题  本注记 第24 单源最短路径  24.1 Bellman?Ford算法  24.2 有向无环图中的单源最短路径问题  24.3 Dijkstra算法  24.4 差分约束和最短路径  24.5 最短路径性质的证明  思考题  本注记 第25 所有结点对的最短路径问题  25.1 最短路径和矩阵乘法  25.2 Floyd?Warshall算法  25.3 用于稀疏图的Johnson算法  思考题  本注记 第26 最大流  26.1 流网络  26.2 Ford\Fulkerson方法  26.3 最大二分匹配  26.4 推送重贴标签算法  26.5 前置重贴标签算法  思考题  本注记 第七部分 算法问题选编 第27 多线程算法  27.1 动态多线程基础  27.2 多线程矩阵乘法  27.3 多线程归并排序  思考题  本注记 第28 矩阵运算  28.1 求解线性方程组  28.2 矩阵求逆  28.3 对称正定矩阵和最小二乘逼近  思考题  本注记 第29 线性规划  29.1 标准型和松弛型  29.2 将问题表达为线性规划  29.3 单纯形算法  29.4 对偶性  29.5 初始基本可行解  思考题  本注记 第30 多项式与快速傅里叶变换  30.1 多项式的表示  30.2 DFT与FFT  30.3 高效FFT实现  思考题  本注记 第31 数论算法  31.1 基础数论概念  31.2 最大公约数  31.3 模运算  31.4 求解模线性方程  31.5 中国余数定理  31.6 元素的幂  31.7 RSA公钥加密系统  31.8 素数的测试  31.9 整数的因子分解  思考题  本注记 第32 字符串匹配  32.1 朴素字符串匹配算法  32.2 Rabin\Karp算法  32.3 利用有限自动机进行字符串匹配  32.4 Knuth?Morris?Pratt算法  思考题  本注记 第33 计算几何学  33.1 线段的性质  33.2 确定任意一对线段是否相交  33.3 寻找凸包  33.4 寻找最近点对  思考题  本注记 第34 NP完全性  34.1 多项式时间  34.2 多项式时间的验证  34.3 NP完全性与可归约性  34.4 NP完全性的证明  34.5 NP完全问题   34.5.1 团问题   34.5.2 顶点覆盖问题   34.5.3 哈密顿回路问题   34.5.4 旅行商问题   34.5.5 子集和问题  思考题  本注记 第35 近似算法  35.1 顶点覆盖问题  35.2 旅行商问题  35.2.1 满足三角不等式的旅行商问题  35.2.2 一般旅行商问题  35.3 集合覆盖问题  35.4 随机化和线性规划  35.5 子集和问题  思考题  本注记 第八部分 附录:数学基础知识 附录A 求和  A.1 求和公式及其性质  A.2 确定求和时间的界  思考题  附录注记 附录B 集合等离散数学内容  B.1 集合  B.2 关系  B.3 函数  B.4 图  B.5 树   B.5.1 自由树   B.5.2 有根树和有序树   B.5.3 二叉树和位置树  思考题  附录注记 附录C 计数与概率  C.1 计数  C.2 概率 C.3 离散随机变量  C.4 几何分布与二项分布  *C.5 二项分布的尾部  思考题  附录注记 附录D 矩阵  D.1 矩阵与矩阵运算  D.2 矩阵基本性质  思考题  附录注记
算法导论英文版,非图片版。 I Foundations Introduction 3 1 The Role of Algorithms in Computing 5 1.1 Algorithms 5 1.2 Algorithms as a technology 11 2 Getting Started 16 2.1 Insertion sort 16 2.2 Analyzing algorithms 23 2.3 Designing algorithms 29 3 Growth of Functions 43 3.1 Asymptotic notation 43 3.2 Standard notations and common functions 53 4 Divide-and-Conquer 65 4.1 The maximum-subarray problem 68 4.2 Strassen’s algorithm for matrix multiplication 75 4.3 The substitution method for solving recurrences 4.4 The recursion-tree method for solving recurrences 88 4.5 The master method for solving recurrences 93 ? 4.6 Proof of the master theorem 97 5 Probabilistic Analysis and Randomized Algorithms 114 5.1 The hiring problem 114 5.2 Indicator random variables 118 5.3 Randomized algorithms 122 ? 5.4 Probabilistic analysis and further uses of indicator random variables 130 83 vi Contents II Sorting and Order Statistics Introduction 147 6 Heapsort 151 6.1 Heaps 151 6.2 Maintaining the heap property 154 6.3 Building a heap 156 6.4 The heapsort algorithm 159 6.5 Priority queues 162 7 Quicksort 170 7.1 Description of quicksort 170 7.2 Performance of quicksort 174 7.3 A randomized version of quicksort 179 7.4 Analysis of quicksort 180 8 Sorting in Linear Time 191 8.1 Lower bounds for sorting 191 8.2 Counting sort 194 8.3 Radix sort 197 8.4 Bucket sort 200 9 Medians and Order Statistics 213 9.1 Minimum and maximum 214 9.2 Selection in expected linear time 215 9.3 Selection in worst-case linear time 220 III Data Structures Introduction 229 10 Elementary Data Structures 232 10.1 Stacks and queues 232 10.2 Linked lists 236 10.3 Implementing pointers and objects 241 10.4 Representing rooted trees 246 11 Hash Tables 253 11.1 Direct-address tables 254 11.2 Hash tables 256 11.3 Hash functions 262 11.4 Open addressing 269 ? 11.5 Perfect hashing 277 Contents vii 12 Binary Search Trees 286 12.1 What is a binary search tree? 286 12.2 Querying a binary search tree 289 12.3 Insertion and deletion 294 ? 12.4 Randomly built binary search trees 299 13 Red-Black Trees 308 13.1 Properties of red-black trees 308 13.2 Rotations 312 13.3 Insertion 315 13.4 Deletion 323 14 Augmenting Data Structures 339 14.1 Dynamic order statistics 339 14.2 How to augment a data structure 345 14.3 Interval trees 348 IV Advanced Design and Analysis Techniques Introduction 357 15 Dynamic Programming 359 15.1 Rod cutting 360 15.2 Matrix-chain multiplication 370 15.3 Elements of dynamic programming 378 15.4 Longest common subsequence 390 15.5 Optimal binary search trees 397 16 Greedy Algorithms 414 16.1 An activity-selection problem 16.2 Elements of the greedy strategy 423 16.3 Huffman codes 428 415 ? 16.4 Matroids and greedy methods 437 ? 16.5 A task-scheduling problem as a matroid 443 17 Amortized Analysis 451 17.1 Aggregate analysis 452 17.2 The accounting method 456 17.3 The potential method 459 17.4 Dynamic tables 463 viii Contents V Advanced Data Structures Introduction 481 18 B-Trees 484 18.1 Definition of B-trees 488 18.2 Basic operations on B-trees 491 18.3 Deleting a key from a B-tree 499 19 Fibonacci Heaps 505 19.1 Structure of Fibonacci heaps 507 19.2 Mergeable-heap operations 510 19.3 Decreasing a key and deleting a node 518 19.4 Bounding the maximum degree 523 20 van Emde Boas Trees 531 20.1 Preliminary approaches 532 20.2 A recursive structure 536 20.3 The van Emde Boas tree 545 21 Data Structures for Disjoint Sets 561 21.1 Disjoint-set operations 561 21.2 Linked-list representation of disjoint sets 564 21.3 Disjoint-set forests 568 ? 21.4 Analysis of union by rank with path compression 573 VI Graph Algorithms Introduction 587 22 Elementary Graph Algorithms 589 22.1 Representations of graphs 589 22.2 Breadth-first search 594 22.3 Depth-first search 22.4 Topological sort 612 22.5 Strongly connected components 615 23 Minimum Spanning Trees 624 23.1 Growing a minimum spanning tree 625 23.2 The algorithms of Kruskal and Prim 631 603 Contents ix 24 Single-Source Shortest Paths 643 24.1 The Bellman-Ford algorithm 651 24.2 Single-source shortest paths in directed acyclic graphs 24.3 Dijkstra’s algorithm 658 24.4 Difference constraints and shortest paths 664 24.5 Proofs of shortest-paths properties 671 655 25 All-Pairs Shortest Paths 684 25.1 Shortest paths and matrix multiplication 25.2 The Floyd-Warshall algorithm 693 25.3 Johnson’s algorithm for sparse graphs 686 700 26 Maximum Flow 708 26.1 Flow networks 709 26.2 The Ford-Fulkerson method 714 26.3 Maximum bipartite matching 732 ? 26.4 Push-relabel algorithms 736 ? 26.5 The relabel-to-front algorithm 748 VII Selected Topics Introduction 769 27 Multithreaded Algorithms 772 27.1 The basics of dynamic multithreading 27.2 Multithreaded matrix multiplication 792 27.3 Multithreaded merge sort 797 28 Matrix Operations 813 28.1 Solving systems of linear equations 813 28.2 Inverting matrices 827 28.3 Symmetric positive-definite matrices and least-squares approximation 832 29 Linear Programming 843 29.1 Standard and slack forms 850 29.2 Formulating problems as linear programs 859 29.3 The simplex algorithm 864 29.4 Duality 879 29.5 The initial basic feasible solution 886 774 x Contents 30 Polynomials and the FFT 898 30.1 Representing polynomials 900 30.2 The DFT and FFT 906 30.3 Efficient FFT implementations 915 31 Number-Theoretic Algorithms 926 31.1 Elementary number-theoretic notions 927 31.2 Greatest common divisor 933 31.3 Modular arithmetic 939 31.4 Solving modular linear equations 946 31.5 The Chinese remainder theorem 950 31.6 Powers of an element 954 31.7 The RSA public-key cryptosystem ? 31.8 Primality testing 965 ? 31.9 Integer factorization 975 958 32 String Matching 985 32.1 The naive string-matching algorithm 988 32.2 The Rabin-Karp algorithm 990 32.3 String matching with finite automata 995 ? 32.4 The Knuth-Morris-Pratt algorithm 1002 33 Computational Geometry 1014 33.1 Line-segment properties 1015 33.2 Determining whether any pair of segments intersects 1021 33.3 Finding the convex hull 1029 33.4 Finding the closest pair of points 1039 34 NP-Completeness 1048 34.1 Polynomial time 1053 34.2 Polynomial-time verification 1061 34.3 NP-completeness and reducibility 1067 34.4 NP-completeness proofs 1078 34.5 NP-complete problems 1086 35 Approximation Algorithms 1106 35.1 The vertex-cover problem 1108 35.2 The traveling-salesman problem 1111 35.3 The set-covering problem 1117 35.4 Randomization and linear programming 1123 35.5 The subset-sum problem 1128 Contents xi VIII Appendix: Mathematical Background Introduction 1143 A Summations 1145 A.1 Summation formulas and properties 1145 A.2 Bounding summations 1149 B Sets, Etc. 1158 B.1 Sets 1158 B.2 Relations 1163 B.3 Functions 1166 B.4 Graphs 1168 B.5 Trees 1173 C Counting and Probability 1183 C.1 Counting 1183 C.2 Probability 1189 C.3 Discrete random variables 1196 C.4 The geometric and binomial distributions 1201 D Matrices 1217 D.1 Matrices and matrix operations 1217 D.2 Basic matrix properties 1222 Bibliography 1231 Index 1251
算法导论,英文 【本书目录】 I Foundations Introduction 3 l The Role of Algorithms in Computing 5 l.l Algorithms 5 l.2 Algorithms as a technology 10 2 Getting Started I5 2.l Insertion sort 15 2.2 Analyzing algorithms 21 2.3 Designing algorithms 27 3 Growth of Functions 41 3.l Asymptotic notation 41 3.2 Standard notations and common functions 51 4 Recurrences 62 4.l The substitution method 63 4.2 The recursion-tree method 67 4.3 The master method 73 4.4 Proof of the master theorem 76 5 Probabilistic Analysis and Randomized Algorithms 5.l The hiring problem 91 5.2 Indicator random variables 94 5.3 Randomized algorithms 99 5.4 Probabi1istic analysis and further uses of indicator 106 II Sorting and Order Statistics Introduction 123 6 Heapsort 127 6.l Heaps I27 6.2 Maintaining the heap property 130 6.3 Building a heap 132 6.4 The heapsort algorithm 135 6.5 Priority queues 138 7 Quicksort 145 7.l Description of quicksort 145 7.2 Performance ofquicksort 149 7.3 A randomized version of quicksort 153 7.4 Analysis ofquicksort 55 8 Sorting in Linear Time 165 8.l Lower bounds for sorting 165 8.2 Counting sort i68 8.3 Radix sort 170 8.4 Bucket sort 174 9 Medians and Order Statistics 183 9.1 Minimum and maximum 184 9.2 Selection in expected linear time 185 9.3 Selection in worst-case linear time 189 III Data Structures Introduction 197 10 Elementary Data Structures 200 l0.l Stacks and queues 200 l0.2 Linked lists 204 l0.3 Implementing pointers and objects 209 l0.4 Representing rooted trees 214 11 Hash Tables 221 ll.l Direct-address tables 222 11.2 Hash tables 224 ll.3 Hash functions 229 ll.4 Open addressing 237 ll.5 Perfect hashing 24S l2 Binary Search Trees 253 l2.l What is a binary search tree? 2S3 l2.2 Querying a binary search tree 2S6 l2.3 Insertion and deletion 261 l2.4 Randoinly built binary search trees 265 13 Red-Black Thees 273 l3.l Properties of red-black trees 273 l3.2 Rotations 277 l3.3 Insertion 280 l3.4 Deletion 288 14 Augmenting Data Structures 302 l4.l Dynamic order statistics 302 l4.2 How to augment a data structure 308 l4.3 Interval trees 311 IV Advanced Desthe and Analysis Techniques Introduction 321 15 Dynamic Programming J2J l5.l Assembly--line scheduling 324 l5.2 Matrix-chain multiplication 331 l5.3 Elements of dynamic programming 339 15.4 Longest common subsequence 350 l5.5 Optimal binary search trees 356 l6 Greedy Algorithms 370 l6.l An activity-selection problem 371 l6.2 Elements of the greedy strategy 379 l6.3 Huffman codes 385 l6.4 Theoretical foundations for greedy methods 393 16.5 A task-scheduling problem 399 17 Amortized Analysis 405 l7.1 Aggregate analysis 406 17.2 The accounting method 410 17.3 The potential method 412 l7.4 Dynamic tables 416 V Advanced Data Structures Introduction 431 18 B-Trees 434 18.l Definition of B--trees 438 l8.2 Basic operations on B-trees 44j l8.3 Deleting a key from a B--tree 449 19 Binomial Heaps 455 l9.l Binomial trees and binomial heaps 457 19.2 Operations on binomial heaps 461 20 Fibonacci Heaps 476 20.l Structure of Fibonacci heaps 477 20.2 Mergeable-heap operations 479 20.3 Decreasing a key and deleting a node 489 20.4 Bounding the maximum degree 493 21 Data Structures for Disjoint Sets 498 2l.l Disjoint--set operations 498 2l.2 Linked-list representation of disjoint sets 501 2l.3 Disjoint--set forests 505 2l.4 Analysis of union by rank with path compression 50 VI Graph Algorithms Introduction 525 22 Elementary Graph Algorithms 527 22.l Representations of graphs 527 22.2 Breadth-first search 531 22.3 Depth-first search 540 22.4 Topological sort 549 22.5 Strongly connected components 552 23 Minimum Spanning Trees 561 23.l Growing a minimum spanning tree 562 23.2 The algorithms of Kruskal and Prim 567 24 Single-Source Shortest Paths 580 24.l The Bellman-Ford algorithm 588 24.2 Single-source shortest paths in directed acyclic graphs 24.3 Dijkstra's algorithm 595 24.4 Difference constraints and shortest paths 601 24.5 Proofs of shortest-paths properties 607 25 All-Pairs Shortest Paths 620 25.l Shortest paths and matrix multiplication 622 25.2 The Floyd-Warshall a1gorithm 629 25.3 Johnson's algorithm for sparse graphs 636 26 Maximum Flow d43 26.l Flow networks 644 26.2 The Ford-Fulkerson method 651 26.3 Maximum bipartite matching 664 26.4 Push--relabel algorithms 669 26.5 The relabel--to-front a1gorithm 68I VII Selected Topics Introduction 701 27 Sorting Networks 704 27.l Comparison networks 704 27.2 The zero-one principle 709 27.3 A bitonic sorting network 712 27.4 A merging network 716 27.5 A sorting network 719 28 Matrix Operations 725 28.l Properties of matrices 725 28.2 Strassen's algorithm for matrix multiplication 735 28.3 Solving systems of linear equations 742 28.4 Inverting matrices 7S5 28.5 Symmetric positive-definite matrices and least-squares approximation760 29 Linear Programming 770 29.1 Standard and slack forms 777 29.2 Formulating problems as linear programs 785 29.3 The simplex algorithm 790 29.4 Duality 804 29.5 The initial basic feasible solution 811 30 Polynomials and the FFT 822 30.l Representation of polynomials 824 30.2 The DFT and FFT 830 30.3 Efficient FFT implementations 839 31 Number-Theoretic Algorithms 849 3l.l E1ementary numbertheoretic notions 850 31.2 Greatest common divisor 856 3l.3 Modular arithmetic 862 3l.4 Solving modular linear equations 869 3l.5 The Chinese remainder theorem 873 3l.6 Powers of an element 876 3l.7 The RSA public-key cryptosystem 881 3l.8 Primality testing 887 3l.9 Integer factorization 896 32 String Matching 906 32.l The naive string-matching algorithm 909 32.2 The Rabin-Karp algorithm 911 32.3 String matching with finite automata 916 32.4 The Knuth-Morris-Pratt algorithm 923 33 Computational Geometry 933 33.l Line--segment properties 934 33.2 Determining whether any pair of segments intersects 940 33.3 Finding the convex hull 947 33.4 Finding the c1osest pair of points 957 34 NP-Completeness 966 34.1 Polynomial time 971 34.2 Polynomial-time verification 979 34.3 NP-completeness and reducibility 984 34.4 NP--completeness proofs 995 34.5 NP-complete problems 1003 35 Approximation Algorithms 1022 35.l The vertex-cover problem 1024 35.2 The traveling-salesman problem 1027 35.3 The set-covering problem 1033 35.4 Randomization and linear programming ]039 35.5 The subset-sum problem 1043 VH APPendir: Mathematical Background Introduction 1057 A Summations 1058 A.l Summation formulas and properties 1058 A.2 Bounding summations 1062 B Sets, Etc. 1070 B.1 Sets 1070 B.2 Relations 1075 B.3 Functions 1077 B.4 Graphs 1080 B.5 Trees 1085 C Counting and Probability 1094 C.l Counting 1094 C.2 Probability 1100 C.3 Discrete random variables 1106 C.4 The geometric and binomial distributions 1112 C.5 The tails of the binomial distribution 1118 Bibliography 1127 Index 1145

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

边懵懵'.ㅅ'

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值