Skip to content

Commit 6e006c3

Browse files
docs: Update dsa-anal: time
1 parent a6f13f5 commit 6e006c3

File tree

7 files changed

+1020
-4
lines changed

7 files changed

+1020
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/site/
33
/env/
44
__pycache__/
5-
uv.lock
65
.roo/
76
docs/projects/log/
87
docs/projects/assets/log/
98
docs/draft/
9+
/en/

docs/credits.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ hide:
3232
[![bash](https://www.vectorlogo.zone/logos/gnu_bash/gnu_bash-ar21.svg)](https://www.gnu.org/software/bash/?utm_source=vectorlogozone&utm_medium=referrer){target="_blank"}
3333
[![bluetooth](https://www.vectorlogo.zone/logos/bluetooth/bluetooth-ar21.svg)](https://www.bluetooth.com/?utm_source=vectorlogozone&utm_medium=referrer){target="_blank"}
3434
[![curl](https://www.vectorlogo.zone/logos/curl_haxx/curl_haxx-ar21.svg)](https://curl.haxx.se/?utm_source=vectorlogozone&utm_medium=referrer){target="_blank"}
35+
[![GeeksforGeeks](https://media.geeksforgeeks.org/gfg-gg-logo.svg)](https://www.geeksforgeeks.org/?utm_source=vectorlogozone&utm_medium=referrer){target="_blank"}
3536
[![debian](https://www.vectorlogo.zone/logos/debian/debian-ar21.svg)](https://www.debian.org/?utm_source=vectorlogozone&utm_medium=referrer){target="_blank"}
3637
[![docker](https://www.vectorlogo.zone/logos/docker/docker-ar21.svg)](https://www.docker.com/?utm_source=vectorlogozone&utm_medium=referrer){target="_blank"}
3738
[![fontawesome](https://www.vectorlogo.zone/logos/font-awesome/font-awesome-ar21.svg)](http://fontawesome.io/?utm_source=vectorlogozone&utm_medium=referrer){target="_blank"}

docs/notes/dsa/anal/time.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,53 @@ $$
9898
\end{aligned}
9999
$$
100100

101-
### 常数阶
101+
### 常数阶 $O(1)$
102+
103+
常数阶的操作数与输入数据量无关,即不随输入数据大小的变化而增大,始终为一个常数。
104+
105+
如普通的赋值语句:
106+
```py
107+
def assign(n: int) -> int:
108+
res = n # 常数阶
109+
return res
110+
```
111+
112+
!!! warning
113+
需要注意的是,常数阶的定义是**操作数量与输入数据大小无关**,因此即便一个程序的输入数据大小很大(必须是一个常量),如下面的例子:
114+
```py
115+
def sum_to_const(n: int) -> int:
116+
"""Sum from 0 with step n, size times."""
117+
count = 0
118+
size = 10000
119+
for _ in range(size):
120+
count += n
121+
return count
122+
```
123+
这是一个求和函数,用于将输入数据`n`相加`size`次。
124+
125+
虽然我们在编写程序时可以将`size`设置得很大,但在程序运行时,无论输入数据的大小如何,求和的操作次数永远只执行`size`次,即**不随输入数据大小的变化而增大**,因此上面示例的时间复杂度只是一个**常数阶**
126+
127+
### 线性阶 $O(n)$
128+
129+
线性阶的操作数与输入数据大小 $n$**线性相关**,常以单层循环的形式出现:
130+
131+
```py
132+
def for_linear(n: int) -> int:
133+
sum = 0
134+
for _ in range(n):
135+
count += 1
136+
return sum
137+
```
138+
139+
线性阶算法常出现在[**线性表**](https://www.geeksforgeeks.org/dsa/introduction-to-linear-data-structures/)的遍历中;在这中情景下,输入数据一般为待遍历线性表的长度(或大小):
140+
```py
141+
def throughout_arr(nums: list[int]) -> int:
142+
count = 0
143+
for num in nums:
144+
count += num
145+
return count
146+
```
147+
148+
### 平方阶 $O(n^2)$
149+
150+
平方阶的操作数可以看作是输入数据大小 $n$ 的一个二次函数,通常出现在**嵌套循环**中。

docs/notes/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ comments: true
7575

7676
<!-- recent_notes_start -->
7777
<ul>
78-
<li><div style="display:flex; justify-content:space-between; align-items:center;"><a href="dsa/anal/time/">算法时间复杂度</a><span style="font-size:0.8em;">2025-08-16</span></div></li>
78+
<li><div style="display:flex; justify-content:space-between; align-items:center;"><a href="dsa/anal/time/">算法时间复杂度</a><span style="font-size:0.8em;">2025-08-20</span></div></li>
7979
<li><div style="display:flex; justify-content:space-between; align-items:center;"><a href="dsa/anal/iter_and_recu/">迭代与递归</a><span style="font-size:0.8em;">2025-08-15</span></div></li>
8080
<li><div style="display:flex; justify-content:space-between; align-items:center;"><a href="tools/git/">Git</a><span style="font-size:0.8em;">2025-08-13</span></div></li>
8181
<li><div style="display:flex; justify-content:space-between; align-items:center;"><a href="tools/linux/tmux/">tmux</a><span style="font-size:0.8em;">2025-08-13</span></div></li>

mkdocs.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ validation:
203203

204204
## Additional configuration
205205
extra:
206+
alternate:
207+
# - name: 简体中文
208+
# link: /
209+
# lang: zh
210+
# - name: English
211+
# link: /en/
212+
# lang: en
206213
status:
207214
new: Recently added
208215
deprecated: Deprecated
@@ -212,6 +219,8 @@ extra:
212219
social:
213220
- icon: fontawesome/brands/github
214221
link: https://github.com/virtualguard101
222+
- icon: fontawesome/brands/x-twitter
223+
link: https://x.com/virtualguardi01
215224

216225
## Page tree
217226
nav:

scripts/hooks/links.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class LinkData:
3636
# link_icon='material/notebook',
3737
# ),
3838
LinkData(
39-
name='Blog with Hexo',
39+
name='Blog with Anime',
4040
url='https://blog.virtualguard101.com',
4141
description='', # 添加描述
4242
button_icon='fontawesome/solid/blog',

0 commit comments

Comments
 (0)