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 版)
网络流算法
217
网络流算法
通常要比
Ford-Fulkerson
算法
性能要好,因为
广度优先搜索
是按照长度来依次求出增广
路径的,而不是像
深度优先搜索
那样花费大量的时间尝试尽可能地接近汇点。
8.2.4 优化
流网络的典型实现方式是使用数组存储信息。我们在这里使用了列表来代替数组,因为
这样不仅可以增加代码的可读性,还有助于读者理解算法如何工作。尽管如此,还是有
必要思考一下,如何优化代码才能获得更大的性能提升。第
2
章中,我们展示了优化
n
位数乘法所带来的
50%
的性能提升。显然,我们也可以编写出更快的代码,但是这样
的代码可读性不仅不高,并且在问题变化时也不易维护。鉴于这种谨慎的心态,
8-4
给出了
Ford-Fulkerson
算法
Java
实现的优化版本。
8-4
:优化过的
Ford-Fulkerson
算法实现
public class Optimized extends FlowNetwork {
int[][] capacity; //
容量。
int[][] flow; //
流。
int[] previous; //
路径上结点的前驱信息。
int[] visited; //
记录是否访问过某个结点
final int QUEUE_SIZE; //
队列的最大规模。
final int queue[]; //
使用循环队列。
//
加载信息。
public Optimized (int n, int s, int t, Iterator<EdgeInfo> ...
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