没有合适的资源?快使用搜索试试~ 我知道了~
首页Python Algorithms, 2nd Edition.pdf
python算法,第2版解释了python算法分析和设计python算法,第2版解释了python算法分析和设计的方法。这本书由《开始的Python》一书的作者Magnus Lie Hetland撰写,重点关注经典算法,但也对基本的算法问题解决技术有了扎实的理解。 这本书以高度可读的方式处理编程和计算机科学中一些最重要和最具挑战性的领域。它涵盖了算法理论和编程实践,演示了理论如何在真实的Python程序中反映出来。解释了内置在Python语言中的著名算法和数据结构,并向用户展示了如何实现和评估其他算法和数据结构。 的方法。这本书由《开始的Python》一书的作者Magnus Lie Hetland撰写,重点关注经典算法,但也对基本的算法问题解决技术有了扎实的理解。 这本书以高度可读的方式处理编程和计算机科学中一些最重要和最具挑战性的领域。它涵盖了算法理论和编程实践,演示了理论如何在真实的Python程序中反映出来。解释了内置在Python语言中的著名算法和数据结构,并向用户展示了如何实现和评估其他算法和数据结构。
资源详情
资源评论
资源推荐

Hetland
Shelve in
Programming Languages/General
User level:
Beginning–Intermediate
www.apress.com
SOURCE CODE ONLINE
BOOKS FOR PROFESSIONALS BY PROFESSIONALS
®
Python Algorithms
Python Algorithms, Second Edition, explains the Python approach to algorithm
analysis and design. Written by Magnus Lie Hetland, author of Beginning Python,
this book is sharply focused on classical algorithms, but it also gives a solid
understanding of fundamental algorithmic problem-solving techniques.
The book deals with some of the most important and challenging areas of
programming and computer science in a highly readable manner. It covers both
algorithmic theory and programming practice, demonstrating how theory is reflected
in real Python programs. Well-known algorithms and data structures that are built
into the Python language are explained, and the user is shown how to implement
and evaluate others that aren’t built into Python.
What You’ll Learn:
• Transform new problems to well-known algorithmic problems with efficient
solutions, or show that the problems belong to classes of problems
thought not to be efficiently solvable
• Analyze algorithms and Python programs using both mathematical tools
and basic experiments and benchmarks
• Understand several classical algorithms and data structures in depth,
and be able to implement these efficiently in Python
• Design and implement new algorithms for new problems, using time-tested
design principles and techniques
• Speed up implementations, using a plethora of tools for high-performance
computing in Python
SECOND
EDITION
RELATED
9781484 200568
55499
ISBN 978-1-4842-0056-8
www.allitebooks.com

v
Contents at a Glance
About the Author ���������������������������������������������������������������������������������������������������������������� xv
About the Technical Reviewer ������������������������������������������������������������������������������������������ xvii
Acknowledgments ������������������������������������������������������������������������������������������������������������� xix
Preface ������������������������������������������������������������������������������������������������������������������������������ xxi
Chapter 1 ■
: Introduction �����������������������������������������������������������������������������������������������������1
Chapter 2 ■ : The Basics �������������������������������������������������������������������������������������������������������9
Chapter 3 ■ : Counting 101 �������������������������������������������������������������������������������������������������43
Chapter 4 ■ : Induction and Recursion ��� and Reduction ����������������������������������������������������67
Chapter 5 ■ : Traversal: The Skeleton Key of Algorithmics �������������������������������������������������93
Chapter 6 ■ : Divide, Combine, and Conquer ���������������������������������������������������������������������115
Chapter 7 ■ : Greed Is Good? Prove It! �����������������������������������������������������������������������������139
Chapter 8 ■ : Tangled Dependencies and Memoization�����������������������������������������������������163
Chapter 9 ■ : From A to B with Edsger and Friends ����������������������������������������������������������187
Chapter 10 ■ : Matchings, Cuts, and Flows ����������������������������������������������������������������������209
Chapter 11 ■ : Hard Problems and (Limited) Sloppiness ��������������������������������������������������227
www.allitebooks.com

■ Contents at a GlanCe
vi
Appendix A ■ : Pedal to the Metal: Accelerating Python ���������������������������������������������������255
Appendix B ■ : List of Problems and Algorithms ���������������������������������������������������������������259
Appendix C ■ : Graph Terminology ������������������������������������������������������������������������������������267
Appendix D ■ : Hints for Exercises ������������������������������������������������������������������������������������273
Index ���������������������������������������������������������������������������������������������������������������������������������289
www.allitebooks.com

1
Chapter 1
Introduction
1. Write down the problem.
2. Think real hard.
3. Write down the solution.
— “The Feynman Algorithm”
as described by Murray Gell-Mann
Consider the following problem: You are to visit all the cities, towns, and villages of, say, Sweden and then return
to your starting point. This might take a while (there are 24,978 locations to visit, after all), so you want to minimize
your route. You plan on visiting each location exactly once, following the shortest route possible. As a programmer,
you certainly don’t want to plot the route by hand. Rather, you try to write some code that will plan your trip for you.
For some reason, however, you can’t seem to get it right. A straightforward program works well for a smaller number
of towns and cities but seems to run forever on the actual problem, and improving the program turns out to be
surprisingly hard. How come?
Actually, in 2004, a team of five researchers
1
found such a tour of Sweden, after a number of other research teams
had tried and failed. The five-man team used cutting-edge software with lots of clever optimizations and tricks of
the trade, running on a cluster of 96 Xeon 2.6GHz workstations. Their software ran from March 2003 until May 2004,
before it finally printed out the optimal solution. Taking various interruptions into account, the team estimated that
the total CPU time spent was about 85 years!
Consider a similar problem: You want to get from Kashgar, in the westernmost region of China, to Ningbo, on the
east coast, following the shortest route possible.
2
Now, China has 3,583,715 km of roadways and 77,834 km of railways,
with millions of intersections to consider and a virtually unfathomable number of possible routes to follow. It might
seem that this problem is related to the previous one, yet this shortest path problem is one solved routinely, with no
appreciable delay, by GPS software and online map services. If you give those two cities to your favorite map service,
you should get the shortest route in mere moments. What’s going on here?
You will learn more about both of these problems later in the book; the first one is called the traveling salesman
(or salesrep) problem and is covered in Chapter 11, while so-called shortest path problems are primarily dealt with
in Chapter 9. I also hope you will gain a rather deep insight into why one problem seems like such a hard nut to
crack while the other admits several well-known, efficient solutions. More importantly, you will learn something
about how to deal with algorithmic and computational problems in general, either solving them efficiently, using
one of the several techniques and algorithms you encounter in this book, or showing that they are too hard and that
approximate solutions may be all you can hope for. This chapter briefly describes what the book is about—what you
can expect and what is expected of you. It also outlines the specific contents of the various chapters to come in case
you want to skip around.
1
David Applegate, Robert Bixby, Vašek Chvátal, William Cook, and Keld Helsgaun
2
Let’s assume that flying isn’t an option.
www.allitebooks.com
剩余302页未读,继续阅读












安全验证
文档复制为VIP权益,开通VIP直接复制

评论0