File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ def test_heapsort_reverse():
121
121
assert heapsort_reverse(l) == sorted (l, reverse = True )
122
122
```
123
123
124
- # python 里的 heapq
124
+ # Python 里的 heapq 模块
125
125
python 其实自带了 heapq 模块,用来实现堆的相关操作,原理是类似的。请你阅读相关文档并使用内置的 heapq 模块完成堆排序。
126
126
一般我们刷题或者写业务代码的时候,使用这个内置的 heapq 模块就够用了。
127
127
@@ -168,7 +168,7 @@ class TopK:
168
168
169
169
def test ():
170
170
import random
171
- i = list (range (1000 ))
171
+ i = list (range (1000 )) # 这里可以是一个可迭代元素,节省内存
172
172
random.shuffle(i)
173
173
_ = TopK(i, 10 )
174
174
print (_.get_topk())
@@ -185,6 +185,7 @@ if __name__ == '__main__':
185
185
- 请你实现一个最小堆,你需要修改那些代码呢?
186
186
- 我们实现的堆排序是 inplace 的吗,如果不是,你能改成 inplace 的吗?
187
187
- 堆排序的时间复杂度是多少? siftup 和 siftdown 的时间复杂度是多少?(小提示:考虑树的高度,它决定了操作次数)
188
+ - 请你思考 Top K 问题的时间复杂度是多少?
188
189
189
190
190
191
# 延伸阅读
You can’t perform that action at this time.
0 commit comments