Mastering Algorithms with Python....2
Introduction....5
How This Book Is Organized....6
Source Code Listings....6
Acknowledgments....9
Table of Contents....10
About the Author....13
About the Technical Reviewer....14
1. Recursion....15
Basics of Recursion....15
Simple Recursion Examples....17
Number of Paths in a Grid....18
H-Tree....20
Tower of Hanoi....23
Application....27
Summary....31
2. Divide and Conquer....33
Guess a Number....33
Merge Sort....35
Quick Sort....42
Multiplication of Two Positive Integers....46
Fast Fourier Transform....52
Application....62
Summary....67
3. Greedy Algorithm....69
Coin Change....70
Class Scheduling....72
Jumping Frog....74
Build TV Towers....78
Minimum Spanning Tree: Kruskals Algorithm....81
Minimum Spanning Tree: Prims Algorithm....95
Application....101
Summary....107
4. Dynamic Programming....108
Fibonacci Number....108
The Generic Way of Designing a Dynamic Programming Solution....112
Longest Common Subsequence and Substring....116
Knapsack....121
Application....127
Summary....136
5. RSA Cryptosystem....137
Caesar Cipher....137
RSA Initial Encounter....138
Greatest Common Divisor....139
Find Prime Numbers....140
An Improved Version of RSA....142
Application....147
Summary....148
6. Monte Carlo....149
Generate a Random Number....149
Test Uniformity and Independence of Random Numbers....151
Examples of Simple Monte Carlo Simulations....156
Monte Carlo Integration....160
How Likely Will It Rain Tomorrow?....165
Metropolis–Hastings....169
Application....173
Summary....177
7. A Tale of Ten Cities....178
A Traveling Consultant: Part 1....179
A Traveling Consultant: Part 2....189
A Traveling Consultant: Part 3....196
Build a Warehouse....204
Group the Cities....209
Application....215
Summary....220
8. Chess....222
Binary Tree and Its Traversals....223
N-ary Tree and Its Traversals....226
Knights Tour....230
Minimum Jumps for a Knight....238
Eight Queens....240
Monte Carlo Tree Search....247
Application....258
Binary Trees and N-ary Trees....258
DFS, BFS, and Backtracking....259
Monte Carlo Tree Search....263
Summary....265
Appendix A: A Quick Review of Python....267
Basic Types and Data Types....267
Boolean Logic and Flow Control....268
Functions....271
Generators....273
Classes....275
Decorators....279
Miscellaneous....282
Appendix B: Environment Setup and Package Installation....284
Appendix C: References....286
Index....287
Gain a solid understanding of algorithms and improve your problem-solving abilities using Python code. With practical examples and clear explanations, this book bridges the gap between dense academic texts and overly simple industry guides.
Focusing on the logic behind essential algorithms such as Breadth First Search (BFS), Depth First Search (DFS), Divide-and-Conquer, Greedy Methods, and Dynamic Programming, the book provides ample examples, from easy to more advanced. By connecting these concepts to real-world examples, such as chess strategies and the Seam Carving, the book helps readers better grasp and apply algorithms. Each chapter also includes fully implemented Python code, making it a practical reference.
Mastering Algorithms with Python is ideal for IT professionals looking to enhance their skills and approach algorithms with clarity and confidence.
Software developers, data scientists, machine learning professionals and any curious learners about computer algorithms.