没有合适的资源?快使用搜索试试~ 我知道了~
首页Python Algorithms - Mastering Basic Algorithms in the Python Language (2014)
Python Algorithms - Mastering Basic Algorithms in the Python Lan...
需积分: 10 16 下载量 201 浏览量
更新于2023-03-16
评论
收藏 4.73MB PDF 举报
Python Algorithms - Mastering Basic Algorithms in the Python Language
资源详情
资源评论
资源推荐
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
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
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
■ 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
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.
剩余302页未读,继续阅读
mhzhang2015
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- 2023年中国辣条食品行业创新及消费需求洞察报告.pptx
- 2023年半导体行业20强品牌.pptx
- 2023年全球电力行业评论.pptx
- 2023年全球网络安全现状-劳动力资源和网络运营的全球发展新态势.pptx
- 毕业设计-基于单片机的液体密度检测系统设计.doc
- 家用清扫机器人设计.doc
- 基于VB+数据库SQL的教师信息管理系统设计与实现 计算机专业设计范文模板参考资料.pdf
- 官塘驿林场林防火(资源监管)“空天地人”四位一体监测系统方案.doc
- 基于专利语义表征的技术预见方法及其应用.docx
- 浅谈电子商务的现状及发展趋势学习总结.doc
- 基于单片机的智能仓库温湿度控制系统 (2).pdf
- 基于SSM框架知识产权管理系统 (2).pdf
- 9年终工作总结新年计划PPT模板.pptx
- Hytera海能达CH04L01 说明书.pdf
- 数据中心运维操作标准及流程.pdf
- 报告模板 -成本分析与报告培训之三.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0