Python Data Structures and Algorithm Analysis (2nd Edition)
This book is a classic textbook on data structures and algorithms using Python. It covers Python basics review, algorithm analysis (Big O notation), fundamental data structures (stacks, queues, lists), recursion, searching and sorting, tree and graph algorithms. Through practical code listings, it helps readers understand how to efficiently implement various abstract data types using Python.
Course Overview
📚 Content Summary
This book is a classic textbook on data structures and algorithms using Python. It covers Python fundamentals review, algorithm analysis (Big O notation), basic data structures (stacks, queues, lists), recursion, searching and sorting, tree and graph algorithms. Through practical code listings, it helps readers understand how to efficiently implement various abstract data types using Python.
Only by deeply understanding data structures and algorithms can one truly master Python.
Author: Bradley N. Miller (Professor Emeritus of Computer Science, Franklin & Marshall College, USA), David L. Ranum (Cognitive Software Engineer at IBM Watson)
Acknowledgments: Thanks to colleague Steve Hubbard for extensive feedback on the first edition and new material for this edition, as well as to peers worldwide who emailed us with corrections and suggestions. Special thanks to Mary, Bob, and others at Java John’s Café in Decatur for allowing us to become "resident authors" during our sabbaticals. Also, heartfelt gratitude to the staff at Franklin, Beedle & Associates (especially Jim Leisy and Tom Sumner) for their enjoyable collaboration. Finally, special thanks to our wives, Jane Miller and Brenda Ranum, whose love and support made this book possible.
🎯 Learning Objectives
- Understand the relationship between computer science, algorithms, and programming, and grasp the concepts of Abstract Data Types (ADT) and information hiding.
- Become proficient in Python's built-in collection data types (lists, tuples, sets, dictionaries) and control structures (loops, conditionals, exception handling).
- Master core aspects of Python object-oriented programming: including class definition, constructors, operator overloading (e.g., fraction addition), application of Euclidean algorithm, and distinction between deep and shallow equality.
- Compare multiple algorithmic approaches: explain four solutions for anagram detection (counting, sorting, brute force, counting) and their corresponding time complexities.
- Quantify Python container performance: understand the Big O efficiency of core operations in Python lists (List) and dictionaries (Dict), and distinguish performance differences between
pop()andpop(i). - Develop performance validation skills: use the
timeitmodule to design experiments verifying consistency between theoretical complexity and actual runtime. - Understand and differentiate the logical characteristics of linear data structures (stacks, queues, deques, lists).
- Implement custom stacks, queues, and deques using Python's basic collections (e.g., lists).
- Apply stacks in expression processing (infix to postfix conversion, postfix evaluation) and queues in system simulation (printer simulation).
- Master the three fundamental principles of recursion: accurately identify and write recursive functions containing base cases, state evolution, and self-calls.
Lessons 共 8 课时 · 预计 24.0h
Lessons
Lesson
This lesson introduces the core principles of computer science, focusing on problem-solving through algorithms, procedural abstraction, and Python’s object-oriented nature. Students will learn to manage complexity by leveraging Python’s dynamic variable references, efficient built-in data structures, and robust error-handling techniques to build reliable, scalable software.
本课程深入探讨了算法分析的核心工具——大O记法,通过异序词检测案例展示了从暴力法到计数法的性能优化过程。学习重点在于理解不同操作(如列表索引与pop操作)的复杂度差异,并掌握如何通过空间换时间及选择合适的数据结构来提升程序效率。
This lesson introduces linear data structures and the concept of Abstract Data Types (ADTs), focusing on the stack as a fundamental LIFO (Last-In, First-Out) structure. Students will learn to implement stacks in Python and apply them to complex tasks, including converting infix expressions to postfix notation and evaluating those expressions efficiently.
本课程深入探讨了递归算法的核心原理,重点讲解了递归三原则(基准情况、状态改变、自我调用)以及递归与系统调用栈之间的内在联系。通过进制转换、汉诺塔及动态规划等案例,学生将学习如何将复杂问题拆解为自相似的子问题,并掌握从递归思维向高效动态规划算法的进阶转换。
This lesson explores fundamental search and retrieval algorithms, progressing from $O(n)$ sequential search to the $O(\log n)$ efficiency of binary search and the $O(1)$ potential of hash tables. Students learn to optimize data access through divide-and-conquer strategies, sophisticated hash function design, and collision-handling techniques to build efficient, dictionary-like data structures.
This lesson explores the hierarchical and recursive nature of tree data structures, covering fundamental terminology, implementation methods like nested lists and object-oriented references, and the construction of expression trees. It also introduces essential tree traversal algorithms—preorder, inorder, and postorder—and explains how these recursive patterns are applied to tasks like file system analysis and AVL tree balancing.
This lesson introduces graph theory as a powerful tool for modeling real-world problems by abstracting entities as vertices and relationships as edges. Students will learn to implement graphs using adjacency lists, compare storage efficiency, and master the Breadth-First Search (BFS) algorithm to solve pathfinding and state-space challenges.
This lesson explores the memory efficiency of Python's ArrayList, explaining how amortized analysis ensures $O(1)$ performance for append operations through strategic over-allocation. It also covers the mathematical foundations of RSA encryption, demonstrating how modular exponentiation and divide-and-conquer algorithms optimize complex calculations for secure data processing.