With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

Book Description

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.

1. Cover
2. Title
4. Dedication
5. Contents at a Glance
6. Contents
9. Acknowledgments
10. Preface
11. Chapter 1: Introduction
1. What’s All This, Then?
2. Why Are You Here?
3. Some Prerequisites
4. What’s in This Book
5. Summary
6. If You’re Curious …
7. Exercises
8. References
12. Chapter 2: The Basics
1. Some Core Ideas in Computing
2. Asymptotic Notation
3. Implementing Graphs and Trees
4. Beware of Black Boxes
5. Summary
6. If You’re Curious …
7. Exercises
8. References
13. Chapter 3: Counting 101
1. The Skinny on Sums
2. A Tale of Two Tournaments
3. Subsets, Permutations, and Combinations
4. Recursion and Recurrences
5. So What Was All That About?
6. Summary
7. If You’re Curious …
8. Exercises
9. References
14. Chapter 4: Induction and Recursion … and Reduction
1. Oh, That’s Easy!
2. One, Two, Many
3. Mirror, Mirror
4. Designing with Induction (and Recursion)
5. Stronger Assumptions
6. Invariants and Correctness
8. Reduction + Contraposition = Hardness Proof
10. Summary
11. If You’re Curious …
12. Exercises
13. References
15. Chapter 5: Traversal: The Skeleton Key of Algorithmics
1. A Walk in the Park
2. Go Deep!
3. Infinite Mazes and Shortest (Unweighted) Paths
4. Strongly Connected Components
5. Summary
6. If You’re Curious …
7. Exercises
8. References
16. Chapter 6: Divide, Combine, and Conquer
1. Tree-Shaped Problems: All About the Balance
2. The Canonical D&C Algorithm
3. Searching by Halves
4. Sorting by Halves
5. Three More Examples
6. Tree Balance … and Balancing*
7. Summary
8. If You’re Curious …
9. Exercises
10. References
17. Chapter 7: Greed Is Good? Prove It!
1. Staying Safe, Step by Step
2. The Knapsack Problem
3. Huffman’s Algorithm
4. Minimum Spanning Trees
5. Greed Works. But When?
6. Summary
7. If You’re Curious …
8. Exercises
9. References
18. Chapter 8: Tangled Dependencies and Memoization
19. Chapter 9: From A to B with Edsger and Friends
20. Chapter 10: Matchings, Cuts, and Flows
21. Chapter 11: Hard Problems and (Limited) Sloppiness
1. Reduction Redux
2. Not in Kansas Anymore?
3. Meanwhile, Back in Kansas …
4. But Where Do You Start? And Where Do You Go from There?
5. A Ménagerie of Monsters
6. When the Going Gets Tough, the Smart Get Sloppy
7. Desperately Seeking Solutions
8. And the Moral of the Story Is …
9. Summary
10. If You’re Curious …
11. Exercises
12. References
22. Appendix A: Pedal to the Metal: Accelerating Python
23. Appendix B: List of Problems and Algorithms
24. Appendix C: Graph Terminology
25. Appendix D: Hints for Exercises
26. Index