diff --git a/docs/chapter_backtracking/n_queens_problem.md b/docs/chapter_backtracking/n_queens_problem.md index ed7c8e536..2c9c2864a 100644 --- a/docs/chapter_backtracking/n_queens_problem.md +++ b/docs/chapter_backtracking/n_queens_problem.md @@ -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)$** 。 diff --git a/docs/chapter_data_structure/number_encoding.assets/1s_2s_complement.png b/docs/chapter_data_structure/number_encoding.assets/1s_2s_complement.png index 369b894ce..16b7ba6ef 100644 Binary files a/docs/chapter_data_structure/number_encoding.assets/1s_2s_complement.png and b/docs/chapter_data_structure/number_encoding.assets/1s_2s_complement.png differ diff --git a/docs/chapter_introduction/algorithms_are_everywhere.assets/greedy_change.png b/docs/chapter_introduction/algorithms_are_everywhere.assets/greedy_change.png index 59b05ed17..fa970c15c 100644 Binary files a/docs/chapter_introduction/algorithms_are_everywhere.assets/greedy_change.png and b/docs/chapter_introduction/algorithms_are_everywhere.assets/greedy_change.png differ diff --git a/docs/chapter_preface/suggestions.md b/docs/chapter_preface/suggestions.md index 30c510feb..421f32acd 100644 --- a/docs/chapter_preface/suggestions.md +++ b/docs/chapter_preface/suggestions.md @@ -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. **阶段三:搭建知识体系**。在学习方面,我们可以阅读算法专栏文章、解题框架和算法教材,以不断丰富知识体系。在刷题方面,可以尝试采用进阶刷题策略,如按专题分类、一题多解、一解多题等,相关的刷题心得可以在各个社区找到。 如下图所示,本书内容主要涵盖“阶段一”,旨在帮助你更高效地展开阶段二和阶段三的学习。 diff --git a/docs/chapter_sorting/quick_sort.assets/pivot_division_step1.png b/docs/chapter_sorting/quick_sort.assets/pivot_division_step1.png index cae41606f..242ff0d0a 100644 Binary files a/docs/chapter_sorting/quick_sort.assets/pivot_division_step1.png and b/docs/chapter_sorting/quick_sort.assets/pivot_division_step1.png differ diff --git a/docs/chapter_sorting/quick_sort.assets/pivot_division_step2.png b/docs/chapter_sorting/quick_sort.assets/pivot_division_step2.png index 02ffa0756..27a829600 100644 Binary files a/docs/chapter_sorting/quick_sort.assets/pivot_division_step2.png and b/docs/chapter_sorting/quick_sort.assets/pivot_division_step2.png differ diff --git a/docs/chapter_sorting/quick_sort.assets/pivot_division_step3.png b/docs/chapter_sorting/quick_sort.assets/pivot_division_step3.png index 58078640e..44a80612d 100644 Binary files a/docs/chapter_sorting/quick_sort.assets/pivot_division_step3.png and b/docs/chapter_sorting/quick_sort.assets/pivot_division_step3.png differ diff --git a/docs/chapter_sorting/quick_sort.assets/pivot_division_step4.png b/docs/chapter_sorting/quick_sort.assets/pivot_division_step4.png index 7964792d8..41af01122 100644 Binary files a/docs/chapter_sorting/quick_sort.assets/pivot_division_step4.png and b/docs/chapter_sorting/quick_sort.assets/pivot_division_step4.png differ diff --git a/docs/chapter_sorting/quick_sort.assets/pivot_division_step5.png b/docs/chapter_sorting/quick_sort.assets/pivot_division_step5.png index 4e0a3a64f..721cd8db7 100644 Binary files a/docs/chapter_sorting/quick_sort.assets/pivot_division_step5.png and b/docs/chapter_sorting/quick_sort.assets/pivot_division_step5.png differ diff --git a/docs/chapter_sorting/quick_sort.assets/pivot_division_step6.png b/docs/chapter_sorting/quick_sort.assets/pivot_division_step6.png index 729d89876..546d67a58 100644 Binary files a/docs/chapter_sorting/quick_sort.assets/pivot_division_step6.png and b/docs/chapter_sorting/quick_sort.assets/pivot_division_step6.png differ diff --git a/docs/chapter_sorting/quick_sort.assets/pivot_division_step7.png b/docs/chapter_sorting/quick_sort.assets/pivot_division_step7.png index 45ec264e4..44975cc82 100644 Binary files a/docs/chapter_sorting/quick_sort.assets/pivot_division_step7.png and b/docs/chapter_sorting/quick_sort.assets/pivot_division_step7.png differ diff --git a/docs/chapter_sorting/quick_sort.assets/pivot_division_step8.png b/docs/chapter_sorting/quick_sort.assets/pivot_division_step8.png index 81657b681..ad2014f8d 100644 Binary files a/docs/chapter_sorting/quick_sort.assets/pivot_division_step8.png and b/docs/chapter_sorting/quick_sort.assets/pivot_division_step8.png differ diff --git a/docs/chapter_stack_and_queue/stack.assets/array_stack_step2_push.png b/docs/chapter_stack_and_queue/stack.assets/array_stack_step2_push.png index 7caf4d72e..6c4cae3fd 100644 Binary files a/docs/chapter_stack_and_queue/stack.assets/array_stack_step2_push.png and b/docs/chapter_stack_and_queue/stack.assets/array_stack_step2_push.png differ