算法与计算机科学interactivepython.org编辑精选
用 Python 解决问题:算法与数据结构
Problem Solving with Algorithms and Data Structures using Python (2015)
2015 — 2018,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是一本免费的在线交互式教材《Problem Solving with Algorithms and Data Structures using Python》,在网页中嵌入可运行的代码示例,讲解栈、队列、递归、排序、树等经典数据结构与算法。它由 Runestone Interactive 平台托管,平台本身也是开源的。
为什么经久不衰:它免费且能在浏览器里直接运行书中代码,多年来一直是用 Python 入门算法与数据结构的经典自学资源;不过评论区也指出其部分代码实现并不严谨,阅读时可带着批判眼光。
HN 评论精选
推荐同风格的 interactive-coding-challenges 仓库,可运行测试即时验证答案。
如果你喜欢这个,我强烈推荐也试试这个:https://github.com/donnemartin/interactive-coding-challenges。它精神相同,有些内容讲得更细,还自带测试,可以运行你的解答来验证正确性并立即获得反馈。
gspetr查看英文原文
If you enjoyed this, I highly recommend also giving this a try: https://github.com/donnemartin/interactive-coding-challenges It's in the same spirit, has some things covered in even more detail and it even has tests you can run on your solutions to verify correctness and instantly receive feedback.
批评书中代码不符合 PEP-8、风格不一致,且实现未利用 Python 特性,质疑其价值。
我打开 1.8.1 节想看第一段带代码的内容,结果代码不符合 PEP-8。粗扫一遍,作者似乎非常抗拒在逗号后加空格,很影响可读性,而且逐行之间都不一致,所以并非风格选择;字符串的单双引号使用也不统一。我跳到「用 Python 实现栈」一节,发现有点奇怪:他们实现的栈类只是列表的薄封装,把 append 别名为 push,把 self.items[len(self.items)-1] 别名为 peek(其实在 Python 里用负索引就能访问列表末尾元素)。这也许显得吹毛求疵,但如果这本书既没利用 Python 的特性、代码又不干净,我不太明白它的价值在哪里。
notafraudster查看英文原文
I opened 1.8.1 because I thought it'd be the first section with code and the code was not PEP-8 compliant. Having a brief scan, the authors seem to have a pretty severe aversion to putting spaces after commas, which is a bummer because it really impacts code readability. It's inconsistent even from line to line, so it's not a style thing. They're also inconsistent about using single and double quotes for strings. I skipped ahead to "implementing a stack in python", which is a little weird because the stack class they implement is just a thin wrapper around lists with append aliased to push and "self.items[len(self.items)-1]" aliased to peek (note: in python you can just use negative indexing to access items near the end of a list) This might seem pedantic, but, like, if the book isn't leveraging Python and it's not particularly clean code then I don't really understand what's on offer here.
指出书中 Queue/Deque 的实现用列表操作导致 O(n) 复杂度,是算法上的错误示范。
讽刺的是,书中给出的 Queue 和 Deque 实现在算法上很糟糕,某些操作是 O(n),而本应是 O(1)。完全可以从第一性原理出发,基于字典或链表来实现 Queue 和 Deque。使用 s.pop(0) 和 s.insert(0, x) 这类列表操作是个错误。
raymondh查看英文原文
Ironically, the provided implementations for Queue and Deque are algorithmically terrible, giving O(n) performance for operations that should be O(1). Queue and Deque could easily be developed from first principles by building on dictionaries or linked lists. It was a mistake to use list operations like s.pop(0) and s.insert(0, x).
该平台开源,欢迎社区参与贡献。
另外,Interactive Python 是开源的!如果你喜欢它,帮忙把它做得更好!https://github.com/RunestoneInteractive
riknos314查看英文原文
Also, Interactive python is open source! If you like it, help make it better! https://github.com/RunestoneInteractive
历次讨论
同类还值得读
位运算技巧集
Bit Twiddling Hacks
斯坦福页面上的经典位运算技巧合集,收录了 popcount、前导/尾随零、位反转、交换、舍入等大量技巧,并附有解释和性能讨论。
算法与计算机科学上首页 8 次 · 2011–2024graphics.stanford.edu编辑精选如何不按平均评分排序
How Not To Sort By Average Rating
经典文章解释了为什么按平均评分排序不可靠:只有少量评价的条目(比如仅一条五星)会轻易排到最前,而评价数量的差异被忽略。
算法与计算机科学上首页 7 次 · 2009–2024evanmiller.org编辑精选数据结构可视化
Data Structure Visualizations
旧金山大学 David Galles 教授制作的数据结构与算法交互式可视化网站,涵盖 B 树、红黑树、排序、图算法等,可逐步操作观察其运行过程。
算法与计算机科学上首页 6 次 · 2011–2021cs.usfca.edu编辑精选1996 年以来的计算机科学最佳论文奖
Best Paper Awards in Computer Science since 1996
Jeff Huang 维护的一个汇总页面,收录了自 1996 年以来计算机科学各主要会议的“最佳论文奖”获奖名单,并按年份和会议整理,方便读者一站式浏览历届获奖论文。
算法与计算机科学上首页 6 次 · 2010–2018jeffhuang.com编辑精选算法(Jeff Erickson)
Algorithms, by Jeff Erickson
伊利诺伊大学 Jeff Erickson 教授的算法课教材,免费在线开放。
算法与计算机科学上首页 5 次 · 2018–2022jeffe.cs.illinois.edu编辑精选