Skip to content

Commit 06b541a

Browse files
committed
feat: update basic sortings and binary tree
1 parent 46930be commit 06b541a

File tree

8 files changed

+239
-146
lines changed

8 files changed

+239
-146
lines changed

README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@ collect some good articles about data structure and algorithm.
1111
![Github Stars](https://img.shields.io/github/stars/chachaxw/data-structure-and-algorithm)
1212
![Github License](https://img.shields.io/github/license/chachaxw/data-structure-and-algorithm)
1313

14-
## 🔗 相关文献(Relative Articles)
14+
## 🔭 学习工具(Learning Tools)
1515

16-
1. [维基百科算法大全](https://zh.wikipedia.org/wiki/Category:算法)
17-
2. [维基百科数据结构大全](https://zh.wikipedia.org/wiki/Category:数据结构)
18-
3. [算法的时间与空间复杂度](https://shimo.im/docs/tMfuE8CWftQyEn1M/)
19-
4. [数据结构的基本知识总结](https://shimo.im/docs/w6lsN96M964doHUE/)
20-
5. [二叉树的遍历详解(前序中序后序层次-递归和非递归)](https://shimo.im/docs/MAbjWlrqWqU1f72m/)
21-
6. [视觉直观感受 7 种常用的排序算法](https://shimo.im/doc/8KWauxFPQUwhe5wI/)
22-
7. [素数生成算法](https://shimo.im/doc/j5MUwPfDObckzUHA/)
23-
8. [红-黑树](https://shimo.im/docs/IdtXEZbkUMQLV54a/)
24-
9. [堆(Heap)](https://shimo.im/docs/aH0fT9Z9trElZgsv)
25-
10. [图解算法数据结构](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/55187i/)
26-
11. [LeetCode 刷题手册](https://books.halfrost.com/leetcode/)
16+
1. [LeetCode](https://leetcode.com)
17+
2. [领扣中国](https://leetcode-cn.com)
18+
3. [C++教程](http://www.runoob.com/cplusplus/cpp-tutorial.html)
19+
4. [看云数据结构与算法/leetcode/lintcode](https://www.kancloud.cn/kancloud/data-structure-and-algorithm-notes)
20+
5. [可视化算法 Algorithm Visualizer](http://algorithm-visualizer.org)
21+
6. [旧金山大学数据结构和算法的可视化学习工具](https://www.cs.usfca.edu/~galles/visualization/source.html)
22+
7. [可视化排序算法 Sorting](http://sorting.at/)
23+
8. [动画学习算法和数据结构 VisulaGo](https://visualgo.net/en)
24+
9. [普林斯顿大学经典算法教材](https://algs4.cs.princeton.edu/home/)
2725

2826
## 🙉 排序算法(Sorting Algorithm)
2927

@@ -50,17 +48,19 @@ collect some good articles about data structure and algorithm.
5048
8. [堆(Heap)](https://zh.wikipedia.org/wiki/堆積)
5149
9. [图(Graph)](<https://zh.wikipedia.org/wiki/图_(数学)>)
5250

53-
## 🔭 学习工具(Learning Tools)
51+
## 🔗 相关文献(Relative Articles)
5452

55-
1. [LeetCode](https://leetcode.com)
56-
2. [领扣中国](https://leetcode-cn.com)
57-
3. [C++教程](http://www.runoob.com/cplusplus/cpp-tutorial.html)
58-
4. [看云数据结构与算法/leetcode/lintcode](https://www.kancloud.cn/kancloud/data-structure-and-algorithm-notes)
59-
5. [可视化算法 Algorithm Visualizer](http://algorithm-visualizer.org)
60-
6. [旧金山大学数据结构和算法的可视化学习工具](https://www.cs.usfca.edu/~galles/visualization/source.html)
61-
7. [可视化排序算法 Sorting](http://sorting.at/)
62-
8. [动画学习算法和数据结构 VisulaGo](https://visualgo.net/en)
63-
9. [普林斯顿大学经典算法教材](https://algs4.cs.princeton.edu/home/)
53+
1. [维基百科算法大全](https://zh.wikipedia.org/wiki/Category:算法)
54+
2. [维基百科数据结构大全](https://zh.wikipedia.org/wiki/Category:数据结构)
55+
3. [算法的时间与空间复杂度](https://shimo.im/docs/tMfuE8CWftQyEn1M/)
56+
4. [数据结构的基本知识总结](https://shimo.im/docs/w6lsN96M964doHUE/)
57+
5. [二叉树的遍历详解(前序中序后序层次-递归和非递归)](https://shimo.im/docs/MAbjWlrqWqU1f72m/)
58+
6. [视觉直观感受 7 种常用的排序算法](https://shimo.im/doc/8KWauxFPQUwhe5wI/)
59+
7. [素数生成算法](https://shimo.im/doc/j5MUwPfDObckzUHA/)
60+
8. [红-黑树](https://shimo.im/docs/IdtXEZbkUMQLV54a/)
61+
9. [堆(Heap)](https://shimo.im/docs/aH0fT9Z9trElZgsv)
62+
10. [图解算法数据结构](https://leetcode-cn.com/leetbook/read/illustration-of-algorithm/55187i/)
63+
11. [LeetCode 刷题手册](https://books.halfrost.com/leetcode/)
6464

6565
## 🏷️ LeetCode 标签(LeetCode Tags)
6666

basic_data_structure/tree/tree.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: Chacha
33
* @Date: 2021-03-05 19:11:18
44
* @Last Modified by: Chacha
5-
* @Last Modified time: 2021-03-07 22:08:29
5+
* @Last Modified time: 2021-03-09 15:18:46
66
*/
77

88
#include <iostream>
@@ -31,7 +31,7 @@ struct TreeNode
3131
* The variable step indicates the distance from the root node and the current node we are visiting.
3232
*/
3333

34-
/*
34+
/* 广度优先搜索
3535
int BFS(TreeNode root, TreeNode target)
3636
{
3737
queue<TreeNode> queue; // store all nodes which are waiting to be processed
@@ -49,6 +49,7 @@ int BFS(TreeNode root, TreeNode target)
4949
{
5050
Node cur = the first node in queue;
5151
return step if cur is target;
52+
5253
for (Node next : the neighbors of cur)
5354
{
5455
add next to queue;
@@ -87,6 +88,7 @@ int BFS(TreeNode root, TreeNode target)
8788
{
8889
Node cur = the first node in queue;
8990
return step if cur is target;
91+
9092
for (Node next : the neighbors of cur)
9193
{
9294
add next to queue;

basic_sorting/bubble_sort.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* @Author: Chacha
33
* @Date: 2018-12-13 22:10:30
44
* @Last Modified by: Chacha
5-
* @Last Modified time: 2021-03-09 11:35:15
5+
* @Last Modified time: 2021-03-09 17:14:13
66
*/
77

88
/**
99
* Bubble Sorting
1010
* Source: https://zh.wikipedia.org/wiki/冒泡排序
1111
*
1212
* Time Complexity: O(n^2)
13-
* Space Complexity: O(n^2)
13+
* Space Complexity: O(1)
1414
*
1515
* 核心:冒泡,持续比较相邻元素,大的挪到后面,因此大的会逐步往后挪,故称之为冒泡。
1616
*/

basic_sorting/merge_sort.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: Chacha
33
* @Date: 2018-12-25 22:53:20
44
* @Last Modified by: Chacha
5-
* @Last Modified time: 2021-03-04 23:19:23
5+
* @Last Modified time: 2021-03-09 13:49:12
66
*/
77

88
#include <iostream>
@@ -13,6 +13,9 @@ using namespace std;
1313
* 归并排序的核心:将两个有序对数组归并成一个更大对有序数组。
1414
* 通常做法为递归排序,并将两个不同的有序数组归并到第三个数组中。
1515
*
16+
* Time Complexity: O(n log n)
17+
* Space Complexity: O(n)
18+
*
1619
* Source:
1720
* https://zh.wikipedia.org/wiki/归并排序
1821
* https://algs4.cs.princeton.edu/22mergesort/

basic_sorting/quick_sort.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: Chacha
33
* @Date: 2018-12-29 23:03:23
44
* @Last Modified by: Chacha
5-
* @Last Modified time: 2019-01-13 08:46:13
5+
* @Last Modified time: 2021-03-10 10:01:20
66
*/
77

88
#include <iostream>
@@ -15,7 +15,7 @@ using namespace std;
1515
* https://algs4.cs.princeton.edu/23quicksort/
1616
*
1717
* Time Complexity: O(n log n) (the badest situation is O(n^2))
18-
* Space Complexity: O (log n)
18+
* Space Complexity: O(log n)
1919
*
2020
* The solution:
2121
* 1. Find a pivot element x;

basic_sorting/selection_sort.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22
* @Author: Chacha
33
* @Date: 2018-12-20 22:00:30
44
* @Last Modified by: Chacha
5-
* @Last Modified time: 2018-12-20 22:39:02
5+
* @Last Modified time: 2021-03-09 14:23:30
66
*/
77

88
/**
99
* Selection Sorting
1010
* Source: https://zh.wikipedia.org/wiki/选择排序
11+
*
12+
* 核心:不断地选择剩余元素中的最小者。
13+
*
14+
* 1. 找到数组中最小元素并将其和数组第一个元素交换位置。
15+
* 2. 在剩下的元素中找到最小元素并将其与数组第二个元素交还,直至整个数组排序。
16+
*
17+
* 性质
18+
* 1. 比较次数 = (n - 1) + (n - 2) + (n - 3) + ... + 2 + 1 ≈ n^2/2
19+
* 2. 交还次数 = N
20+
* 3. 运行时间与输入无关
21+
* 4. 数据移动最少
1122
*/
1223

1324
#include <iostream>

basic_sorting/sorting_selection.gif

41.2 KB
Loading

0 commit comments

Comments
 (0)