Skip to content

Commit

Permalink
Bug fixes and improvements (krahets#1092)
Browse files Browse the repository at this point in the history
* Bug fixes

* Bug fixes

* Reduce figures size

* Update LeetCode problems repo in suggestions.md

* Fix the figures of pivot_division_steps
  • Loading branch information
krahets authored Feb 22, 2024
1 parent 507357a commit 799da32
Show file tree
Hide file tree
Showing 13 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/chapter_backtracking/n_queens_problem.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
[file]{n_queens}-[class]{}-[func]{n_queens}
```

逐行放置 $n$ 次,考虑列约束,则从第一行到最后一行分别有 $n$、$n-1$、$\dots$、$2$、$1$ 个选择,使用 $O(n!)$ 时间;当保存解时,需要复制矩阵 `state` 并添加进 `res` ,复制操作使用 $O(n^2)$ 时间;因此总体时间复杂度为 $O(n! \cdot n^2)$ 。实际上,根据对角线约束的剪枝也能够大幅缩小搜索空间,因而搜索效率往往优于以上时间复杂度。
逐行放置 $n$ 次,考虑列约束,则从第一行到最后一行分别有 $n$、$n-1$、$\dots$、$2$、$1$ 个选择,使用 $O(n!)$ 时间。当记录解时,需要复制矩阵 `state` 并添加进 `res` ,复制操作使用 $O(n^2)$ 时间。因此,**总体时间复杂度为 $O(n! \cdot n^2)$** 。实际上,根据对角线约束的剪枝也能够大幅缩小搜索空间,因而搜索效率往往优于以上时间复杂度。

数组 `state` 使用 $O(n^2)$ 空间,数组 `cols``diags1``diags2` 皆使用 $O(n)$ 空间。最大递归深度为 $n$ ,使用 $O(n)$ 栈帧空间。因此,**空间复杂度为 $O(n^2)$**
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/chapter_preface/suggestions.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ git clone https://github.com/krahets/hello-algo.git
从总体上看,我们可以将学习数据结构与算法的过程划分为三个阶段。

1. **阶段一:算法入门**。我们需要熟悉各种数据结构的特点和用法,学习不同算法的原理、流程、用途和效率等方面的内容。
2. **阶段二:刷算法题**。建议从热门题目开刷,如“[剑指 Offer](https://leetcode.cn/studyplan/coding-interviews/)”和“[LeetCode Hot 100](https://leetcode.cn/studyplan/top-100-liked/)”,先积累至少 100 道题目,熟悉主流的算法问题。初次刷题时,“知识遗忘”可能是一个挑战,但请放心,这是很正常的。我们可以按照“艾宾浩斯遗忘曲线”来复习题目,通常在进行 3~5 轮的重复后,就能将其牢记在心。
2. **阶段二:刷算法题**。建议从热门题目开刷,推荐的题单、题解和刷题计划和请见此 [GitHub 仓库](https://github.com/krahets/LeetCode-Book)。初次刷题时,“知识遗忘”可能是一个挑战,但请放心,这是很正常的。我们可以按照“艾宾浩斯遗忘曲线”来复习题目,通常在进行 3~5 轮的重复后,就能将其牢记在心。
3. **阶段三:搭建知识体系**。在学习方面,我们可以阅读算法专栏文章、解题框架和算法教材,以不断丰富知识体系。在刷题方面,可以尝试采用进阶刷题策略,如按专题分类、一题多解、一解多题等,相关的刷题心得可以在各个社区找到。

如下图所示,本书内容主要涵盖“阶段一”,旨在帮助你更高效地展开阶段二和阶段三的学习。
Expand Down
Binary file modified docs/chapter_sorting/quick_sort.assets/pivot_division_step1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/chapter_sorting/quick_sort.assets/pivot_division_step2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/chapter_sorting/quick_sort.assets/pivot_division_step3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/chapter_sorting/quick_sort.assets/pivot_division_step4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/chapter_sorting/quick_sort.assets/pivot_division_step5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/chapter_sorting/quick_sort.assets/pivot_division_step6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/chapter_sorting/quick_sort.assets/pivot_division_step7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/chapter_sorting/quick_sort.assets/pivot_division_step8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 799da32

Please sign in to comment.