Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Bradley N. Miller, David L. Ranum

Rating No ratings yet

了解数据结构与算法是透彻理解计算机科学的前提。随着Python日益广泛的应用,Python程序员需要实现与传统的面向对象编程语言相似的数据结构与算法。本书是用Python描述数据结构与算法的开山之作,汇聚了作者多年的实战经验,向读者透彻讲解在Python环境下,如何通过一系列存储机制高效地实现各类算法。通过本书,读者将深刻理解Python数据结构、递归、搜索、排序、树与图的应用,等等。

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on introduction to data structures and algorithms written specifically for Python programmers, teaching you to build stacks, queues, trees, and graphs from scratch while analyzing their performance. Best for Python developers who can already write code but want to understand what happens under the hood. 【Book Arc】 - **Opening (~0%–15%)**: Frames computer science as the study of problems, solutions, and abstraction, then reviews the Python basics (references, control flow, functions, classes, exceptions) you'll need throughout. - **Early (~15%–35%)**: Introduces algorithm analysis — Big-O notation, growth rates, and best/worst/average cases — then builds the fundamental linear structures: stacks, queues, deques, and linked lists, using concrete applications like base conversion and palindrome checking. - **Middle (~35%–55%)**: Covers recursion through its three governing principles, then applies it to searching (linear and binary search) and sorting, plus hashing and collision resolution. - **Late (~55%–80%)**: Moves into nonlinear structures — trees (including binary search trees and balanced variants) and graphs — along with their traversal and search algorithms. - **Ending (~80%–100%)**: The excerpts do not cover the final chapters in detail; based on the table of contents, expect advanced topics such as additional tree/graph algorithms and a capstone on problem-solving strategies. 【Key Takeaways】 - **Abstraction separates interface from implementation** (Opening): the driver-versus-mechanic analogy teaches you to use a data structure through its operations without knowing its internals — the core mindset for everything that follows. - **Big-O describes growth, not speed** (Early): constants and lower-order terms fade as input grows, so T(n) = 5n² + 27n + 1005 is simply O(n²); this lens lets you compare algorithms independent of hardware. - **The same ADT can have very different costs depending on implementation** (Early): a list-backed queue gives O(n) enqueue but O(1) dequeue, while a linked list trades those costs — implementation choices matter. - **Recursion rests on three rules** (Middle): a base case, progress toward it, and a recursive call; violating any one produces infinite loops or wrong answers. - **Greedy algorithms can fail** (Middle): the coin-change example shows that always taking the largest coin is optimal for US denominations but breaks once a 21-cent coin exists — motivating dynamic programming. - **Divide and conquer halves the problem** (Middle): binary search repeatedly splits the list, yielding O(log n) comparisons, a template reused in sorting and tree operations. - **Linked structures require careful pointer ordering** (Early): in the `add` method, linking the new node before reassigning the head is essential — reversing the steps loses the entire list. - **Hashing trades space for speed** (Middle): hash tables achieve near-constant lookup, but collisions must be resolved (e.g., linear probing), which affects performance. 【Reading Tips】 - **Deep-read the analysis chapters**: Big-O and recursion principles are the conceptual backbone; skimming them will make later chapters feel like memorization. - **Type out the code**: the book builds structures incrementally (Stack, Queue, Deque, UnorderedList), so running and modifying each implementation cements the pointer logic. - **Do the programming exercises**: they extend core classes (e.g., implementing `__sub__`, `__mul__`, or a full adder circuit) and are where the real learning happens. - **Skim the Python-basics review** if you're already fluent, but check the sections on references and dynamic typing — they explain subtle behaviors later code relies on. - **Use the coin-change and maze examples as mental models** for recognizing when greedy fails and when recursion or dynamic programming is needed. 【Coverage Limits】 The excerpts concentrate on the opening through middle chapters (Python basics, algorithm analysis, linear structures, recursion, searching, sorting, hashing). Trees, graphs, and the book's final chapters are only partially represented, so this guide's later-stage descriptions are inferred from the table of contents rather than detailed content.
Excerpt 1
.... 57 5 3.3 栈 ............................................................. 9 1.4.1 数据 ............................................... 58 5 3.3.1 何谓栈 ........
View in text
Excerpt 2
样执行加法运算,但是还有一处可以改进。1/4+1/2 的确 等于 6/8,但它并不是最简分数。最好的表达应该是 3/4。为了保证结果总是最简分数,需要一个 知道如何化简分数的辅助方法。该方法需要寻找分子和分母的最大公因数(greatest common divisor,GCD),然后将分子和分母分别除以最大公因数...
View in text
Excerpt 3
eturn self.items == [] 7 8 def enqueue(self, item): 9 self.items.insert(0, item) 10 11 def dequeue(self): 12 return self.items.pop() 13 14 def size(self): 15...
View in text
Excerpt 4
算法时一样,让我们来看看上述算法的基本情况,其中一些可以根据之前的 描述猜到。这个算法需要考虑以下 4 种基本情况。 (1) 小乌龟遇到了墙。由于格子被墙堵上,因此无法再继续探索。 (2) 小乌龟遇到了已经走过的格子。在这种情况下,我们不希望它继续探索,不然会陷入循环。 8 124 第 4 章 递归 本书的一个目...
View in text
Excerpt 5
166 第6章 树 HTML 源代码与对应的树展示了另一种层级关系。树的每一层对应 HTML 标签的每一层嵌 套。在源代码中,第一个标签是<html>,最后一个是</html>。其余的标签都在这一对标签之 内。检查一遍会发现,树的每一层都具备这种嵌套属性。 6.3 术语及定义 在看了一些树的例子之后,现在来正式地...
View in text
Excerpt 6
entNode.isLeftChild(): 4 currentNode.leftChild.parent = currentNode.parent 5 currentNode.parent.leftChild = currentNode.leftChild 6 elif currentNode.isRightC...
View in text
Excerpt 7
、 5 如何高效地计算 xn ?二、如何能在不必算出所有 598 743 位数的前提下,计算 xn (mod p) ? 运用上述第 3 条同余定理,不难解决第 2 个问题。 (1) 将 result 初始化为 1。 (2) 重复 n 次: 6 (a) 用 result 乘以 x; (b) 对 result 进行取...
View in text
Excerpt 8
8.6.4 使用图:KMP 8.6.2 节中的模式匹配器将文本中的每个可能匹配成功的子串都与模式比较。这样做往往是 在浪费时间,因为匹配的实际起点远在之后。一种改善措施是,如果不匹配,就以多于一个字母 的幅度滑动模式。图 8-24 展示了这种策略,将模式滑到前一次发生不匹配的位置。 图 8-24 滑动幅度更大的模...
View in text
Tags
AI categories
PythonAlgorithmProgramming Language
Publish Year: 2019
Language: English
Pages: 296
File Format: PDF
File Size: 10.3 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…