Update README for zh-hant version (#1228)
* Bug fixes * Fix the term in heap figures * Unify the font of the chapter covers for the zh, en, and zh-Hant version * Sync the zh-hant vertion with the main branch * Update README for testing * Update README for testing * Update README for testing * Update README for zh, en, zh-hant version * Fix the issue links * Update README * Update README * edition -> version
22
README.md
@ -4,7 +4,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://readme-typing-svg.demolab.com?font=Noto+Sans+SC&weight=500&duration=3500&pause=2000&color=21C8B8¢er=true&vCenter=true&random=false&width=200&lines=Hello%2C+%E7%AE%97%E6%B3%95+!" alt="hello-algo-typing-svg" />
|
<img style="height: 60px;" src="https://readme-typing-svg.demolab.com?font=Noto+Sans+SC&weight=400&duration=3500&pause=2000&color=21C8B8¢er=true&vCenter=true&random=false&width=200&lines=Hello%2C+%E7%AE%97%E6%B3%95+!" alt="hello-algo-typing-svg" />
|
||||||
</br>
|
</br>
|
||||||
动画图解、一键运行的数据结构与算法教程
|
动画图解、一键运行的数据结构与算法教程
|
||||||
</p>
|
</p>
|
||||||
@ -14,13 +14,11 @@
|
|||||||
<img src="https://www.hello-algo.com/index.assets/btn_read_online_dark.svg" width="145"></a>
|
<img src="https://www.hello-algo.com/index.assets/btn_read_online_dark.svg" width="145"></a>
|
||||||
<a href="https://github.com/krahets/hello-algo/releases">
|
<a href="https://github.com/krahets/hello-algo/releases">
|
||||||
<img src="https://www.hello-algo.com/index.assets/btn_download_pdf_dark.svg" width="145"></a>
|
<img src="https://www.hello-algo.com/index.assets/btn_download_pdf_dark.svg" width="145"></a>
|
||||||
<a href="https://github.com/krahets/hello-algo/blob/main/en/README.md">
|
|
||||||
<img src="https://www.hello-algo.com/index.assets/btn_english_edition_dark.svg" width="145"></a>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://www.hello-algo.com/index.assets/animation.gif" width="396">
|
<img src="https://www.hello-algo.com/index.assets/animation.gif" width="389">
|
||||||
<img src="https://www.hello-algo.com/index.assets/running_code.gif" width="396">
|
<img src="https://www.hello-algo.com/index.assets/running_code.gif" width="389">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@ -35,8 +33,20 @@
|
|||||||
<img src="https://img.shields.io/badge/Dart-snow?logo=dart&logoColor=0175C2">
|
<img src="https://img.shields.io/badge/Dart-snow?logo=dart&logoColor=0175C2">
|
||||||
<img src="https://img.shields.io/badge/Rust-snow?logo=rust&logoColor=000000">
|
<img src="https://img.shields.io/badge/Rust-snow?logo=rust&logoColor=000000">
|
||||||
<img src="https://img.shields.io/badge/C-snow?logo=c&logoColor=A8B9CC">
|
<img src="https://img.shields.io/badge/C-snow?logo=c&logoColor=A8B9CC">
|
||||||
|
<img src="https://img.shields.io/badge/Kotlin-snow?logo=kotlin&logoColor=7F52FF">
|
||||||
<img src="https://img.shields.io/badge/Zig-snow?logo=zig&logoColor=F7A41D">
|
<img src="https://img.shields.io/badge/Zig-snow?logo=zig&logoColor=F7A41D">
|
||||||
<img src="https://img.shields.io/badge/Stay%20Tuned-snow">
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
简体中文
|
||||||
|
|
|
||||||
|
<a href="https://github.com/krahets/hello-algo/blob/main/zh-hant/README.md">
|
||||||
|
繁體中文
|
||||||
|
</a>
|
||||||
|
|
|
||||||
|
<a href="https://github.com/krahets/hello-algo/blob/main/en/README.md">
|
||||||
|
English
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## 关于本书
|
## 关于本书
|
||||||
|
@ -106,7 +106,7 @@ def log_recur(n)
|
|||||||
log_recur(n / 2) + 1
|
log_recur(n / 2) + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
### 线性对数阶
|
### 线性对数阶 ###
|
||||||
def linear_log_recur(n)
|
def linear_log_recur(n)
|
||||||
return 1 unless n > 1
|
return 1 unless n > 1
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ Author: Xuan Khoa Tu Nguyen (ngxktuzkai2000@gmail.com)
|
|||||||
=end
|
=end
|
||||||
|
|
||||||
### 生成一个数组,元素为: 1, 2, ..., n ,顺序被打乱 ###
|
### 生成一个数组,元素为: 1, 2, ..., n ,顺序被打乱 ###
|
||||||
def random_number(n)
|
def random_numbers(n)
|
||||||
# 生成数组 nums =: 1, 2, 3, ..., n
|
# 生成数组 nums =: 1, 2, 3, ..., n
|
||||||
nums = Array.new(n) { |i| i + 1 }
|
nums = Array.new(n) { |i| i + 1 }
|
||||||
# 随机打乱数组元素
|
# 随机打乱数组元素
|
||||||
@ -27,7 +27,7 @@ end
|
|||||||
|
|
||||||
for i in 0...10
|
for i in 0...10
|
||||||
n = 100
|
n = 100
|
||||||
nums = random_number(n)
|
nums = random_numbers(n)
|
||||||
index = find_one(nums)
|
index = find_one(nums)
|
||||||
puts "\n数组 [ 1, 2, ..., n ] 被打乱后 = #{nums}"
|
puts "\n数组 [ 1, 2, ..., n ] 被打乱后 = #{nums}"
|
||||||
puts "数字 1 的索引为 #{index}"
|
puts "数字 1 的索引为 #{index}"
|
||||||
|
Before Width: | Height: | Size: 113 KiB After Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 125 KiB After Width: | Height: | Size: 126 KiB |
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 127 KiB |
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 94 KiB |
Before Width: | Height: | Size: 142 KiB After Width: | Height: | Size: 143 KiB |
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 164 KiB |
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 84 KiB |
Before Width: | Height: | Size: 135 KiB After Width: | Height: | Size: 136 KiB |
Before Width: | Height: | Size: 137 KiB After Width: | Height: | Size: 137 KiB |
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 109 KiB |
Before Width: | Height: | Size: 136 KiB After Width: | Height: | Size: 136 KiB |
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 119 KiB |
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 129 KiB |
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 91 KiB |
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 103 KiB |
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 118 KiB |
@ -27,18 +27,18 @@
|
|||||||
| big-$O$ notation | 大 $O$ 记号 | 大 $O$ 記號 |
|
| big-$O$ notation | 大 $O$ 记号 | 大 $O$ 記號 |
|
||||||
| asymptotic upper bound | 渐近上界 | 漸近上界 |
|
| asymptotic upper bound | 渐近上界 | 漸近上界 |
|
||||||
| sign-magnitude | 原码 | 原碼 |
|
| sign-magnitude | 原码 | 原碼 |
|
||||||
| 1’s complement | 反码 | 反碼 |
|
| 1’s complement | 反码 | 一補數 |
|
||||||
| 2’s complement | 补码 | 補碼 |
|
| 2’s complement | 补码 | 二補數 |
|
||||||
| array | 数组 | 陣列 |
|
| array | 数组 | 陣列 |
|
||||||
| index | 索引 | 索引 |
|
| index | 索引 | 索引 |
|
||||||
| linked list | 链表 | 鏈結串列 |
|
| linked list | 链表 | 鏈結串列 |
|
||||||
| linked list node, list node | 链表节点 | 鏈結串列節點 |
|
| linked list node, list node | 链表节点 | 鏈結串列節點 |
|
||||||
| head node | 头节点 | 頭節點 |
|
| head node | 头节点 | 頭節點 |
|
||||||
| tail node | 尾节点 | 尾節點 |
|
| tail node | 尾节点 | 尾節點 |
|
||||||
| list | 列表 | 列表 |
|
| list | 列表 | 串列 |
|
||||||
| dynamic array | 动态数组 | 動態陣列 |
|
| dynamic array | 动态数组 | 動態陣列 |
|
||||||
| hard disk | 硬盘 | 硬碟 |
|
| hard disk | 硬盘 | 硬碟 |
|
||||||
| random-access memory (RAM) | 内存 | 內存 |
|
| random-access memory (RAM) | 内存 | 記憶體 |
|
||||||
| cache memory | 缓存 | 快取 |
|
| cache memory | 缓存 | 快取 |
|
||||||
| cache miss | 缓存未命中 | 快取未命中 |
|
| cache miss | 缓存未命中 | 快取未命中 |
|
||||||
| cache hit rate | 缓存命中率 | 快取命中率 |
|
| cache hit rate | 缓存命中率 | 快取命中率 |
|
||||||
|
@ -563,13 +563,13 @@
|
|||||||
// 执行某些操作
|
// 执行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 循环 O(1) */
|
/* 循环的空间复杂度为 O(1) */
|
||||||
void loop(int n) {
|
void loop(int n) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 递归 O(n) */
|
/* 递归的空间复杂度为 O(n) */
|
||||||
void recur(int n) {
|
void recur(int n) {
|
||||||
if (n == 1) return;
|
if (n == 1) return;
|
||||||
return recur(n - 1);
|
return recur(n - 1);
|
||||||
@ -583,13 +583,13 @@
|
|||||||
// 执行某些操作
|
// 执行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 循环 O(1) */
|
/* 循环的空间复杂度为 O(1) */
|
||||||
void loop(int n) {
|
void loop(int n) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
function();
|
function();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 递归 O(n) */
|
/* 递归的空间复杂度为 O(n) */
|
||||||
void recur(int n) {
|
void recur(int n) {
|
||||||
if (n == 1) return;
|
if (n == 1) return;
|
||||||
return recur(n - 1);
|
return recur(n - 1);
|
||||||
@ -603,13 +603,13 @@
|
|||||||
// 执行某些操作
|
// 执行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 循环 O(1) */
|
/* 循环的空间复杂度为 O(1) */
|
||||||
void Loop(int n) {
|
void Loop(int n) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
Function();
|
Function();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 递归 O(n) */
|
/* 递归的空间复杂度为 O(n) */
|
||||||
int Recur(int n) {
|
int Recur(int n) {
|
||||||
if (n == 1) return 1;
|
if (n == 1) return 1;
|
||||||
return Recur(n - 1);
|
return Recur(n - 1);
|
||||||
@ -624,14 +624,14 @@
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 循环 O(1) */
|
/* 循环的空间复杂度为 O(1) */
|
||||||
func loop(n int) {
|
func loop(n int) {
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
function()
|
function()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 递归 O(n) */
|
/* 递归的空间复杂度为 O(n) */
|
||||||
func recur(n int) {
|
func recur(n int) {
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
return
|
return
|
||||||
@ -649,14 +649,14 @@
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 循环 O(1) */
|
/* 循环的空间复杂度为 O(1) */
|
||||||
func loop(n: Int) {
|
func loop(n: Int) {
|
||||||
for _ in 0 ..< n {
|
for _ in 0 ..< n {
|
||||||
function()
|
function()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 递归 O(n) */
|
/* 递归的空间复杂度为 O(n) */
|
||||||
func recur(n: Int) {
|
func recur(n: Int) {
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
return
|
return
|
||||||
@ -672,13 +672,13 @@
|
|||||||
// 执行某些操作
|
// 执行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 循环 O(1) */
|
/* 循环的空间复杂度为 O(1) */
|
||||||
function loop(n) {
|
function loop(n) {
|
||||||
for (let i = 0; i < n; i++) {
|
for (let i = 0; i < n; i++) {
|
||||||
constFunc();
|
constFunc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 递归 O(n) */
|
/* 递归的空间复杂度为 O(n) */
|
||||||
function recur(n) {
|
function recur(n) {
|
||||||
if (n === 1) return;
|
if (n === 1) return;
|
||||||
return recur(n - 1);
|
return recur(n - 1);
|
||||||
@ -692,13 +692,13 @@
|
|||||||
// 执行某些操作
|
// 执行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 循环 O(1) */
|
/* 循环的空间复杂度为 O(1) */
|
||||||
function loop(n: number): void {
|
function loop(n: number): void {
|
||||||
for (let i = 0; i < n; i++) {
|
for (let i = 0; i < n; i++) {
|
||||||
constFunc();
|
constFunc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 递归 O(n) */
|
/* 递归的空间复杂度为 O(n) */
|
||||||
function recur(n: number): void {
|
function recur(n: number): void {
|
||||||
if (n === 1) return;
|
if (n === 1) return;
|
||||||
return recur(n - 1);
|
return recur(n - 1);
|
||||||
@ -712,13 +712,13 @@
|
|||||||
// 执行某些操作
|
// 执行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 循环 O(1) */
|
/* 循环的空间复杂度为 O(1) */
|
||||||
void loop(int n) {
|
void loop(int n) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
function();
|
function();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 递归 O(n) */
|
/* 递归的空间复杂度为 O(n) */
|
||||||
void recur(int n) {
|
void recur(int n) {
|
||||||
if (n == 1) return;
|
if (n == 1) return;
|
||||||
return recur(n - 1);
|
return recur(n - 1);
|
||||||
@ -732,13 +732,13 @@
|
|||||||
// 执行某些操作
|
// 执行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 循环 O(1) */
|
/* 循环的空间复杂度为 O(1) */
|
||||||
fn loop(n: i32) {
|
fn loop(n: i32) {
|
||||||
for i in 0..n {
|
for i in 0..n {
|
||||||
function();
|
function();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 递归 O(n) */
|
/* 递归的空间复杂度为 O(n) */
|
||||||
fn recur(n: i32) {
|
fn recur(n: i32) {
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
return;
|
return;
|
||||||
@ -754,13 +754,13 @@
|
|||||||
// 执行某些操作
|
// 执行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 循环 O(1) */
|
/* 循环的空间复杂度为 O(1) */
|
||||||
void loop(int n) {
|
void loop(int n) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 递归 O(n) */
|
/* 递归的空间复杂度为 O(n) */
|
||||||
void recur(int n) {
|
void recur(int n) {
|
||||||
if (n == 1) return;
|
if (n == 1) return;
|
||||||
return recur(n - 1);
|
return recur(n - 1);
|
||||||
@ -774,13 +774,13 @@
|
|||||||
// 执行某些操作
|
// 执行某些操作
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
/* 循环 O(1) */
|
/* 循环的空间复杂度为 O(1) */
|
||||||
fun loop(n: Int) {
|
fun loop(n: Int) {
|
||||||
for (i in 0..<n) {
|
for (i in 0..<n) {
|
||||||
function()
|
function()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 递归 O(n) */
|
/* 递归的空间复杂度为 O(n) */
|
||||||
fun recur(n: Int) {
|
fun recur(n: Int) {
|
||||||
if (n == 1) return
|
if (n == 1) return
|
||||||
return recur(n - 1)
|
return recur(n - 1)
|
||||||
|
@ -743,7 +743,7 @@ $$
|
|||||||
|
|
||||||
$T(n)$ 是一次函数,说明其运行时间的增长趋势是线性的,因此它的时间复杂度是线性阶。
|
$T(n)$ 是一次函数,说明其运行时间的增长趋势是线性的,因此它的时间复杂度是线性阶。
|
||||||
|
|
||||||
我们将线性阶的时间复杂度记为 $O(n)$ ,这个数学符号称为<u>大$O$ 记号(big-$O$ notation)</u>,表示函数 $T(n)$ 的<u>渐近上界(asymptotic upper bound)</u>。
|
我们将线性阶的时间复杂度记为 $O(n)$ ,这个数学符号称为<u>大 $O$ 记号(big-$O$ notation)</u>,表示函数 $T(n)$ 的<u>渐近上界(asymptotic upper bound)</u>。
|
||||||
|
|
||||||
时间复杂度分析本质上是计算“操作数量 $T(n)$”的渐近上界,它具有明确的数学定义。
|
时间复杂度分析本质上是计算“操作数量 $T(n)$”的渐近上界,它具有明确的数学定义。
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
30
en/README.md
@ -4,7 +4,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://readme-typing-svg.demolab.com?font=Noto+Sans+SC&weight=500&duration=3500&pause=2000&color=21C8B8¢er=true&vCenter=true&random=false&width=200&lines=Hello%2C+Algo+!" alt="hello-algo-typing-svg" />
|
<img style="height: 60px;" src="https://readme-typing-svg.demolab.com?font=Noto+Sans+SC&weight=500&duration=3500&pause=2000&color=21C8B8¢er=true&vCenter=true&random=false&width=200&lines=Hello%2C+Algo+!" alt="hello-algo-typing-svg" />
|
||||||
</br>
|
</br>
|
||||||
Data Structures and Algorithms Crash Course with Animated Illustrations and Off-the-Shelf Code
|
Data Structures and Algorithms Crash Course with Animated Illustrations and Off-the-Shelf Code
|
||||||
</p>
|
</p>
|
||||||
@ -12,15 +12,11 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://www.hello-algo.com/en/">
|
<a href="https://www.hello-algo.com/en/">
|
||||||
<img src="https://www.hello-algo.com/en/index.assets/btn_read_online_dark.svg" width="120"></a>
|
<img src="https://www.hello-algo.com/en/index.assets/btn_read_online_dark.svg" width="120"></a>
|
||||||
<a href="https://github.com/krahets/hello-algo/releases">
|
|
||||||
<img src="https://www.hello-algo.com/en/index.assets/btn_download_pdf_dark.svg" width="120"></a>
|
|
||||||
<a href="https://github.com/krahets/hello-algo">
|
|
||||||
<img src="https://www.hello-algo.com/en/index.assets/btn_chinese_edition_dark.svg" width="120"></a>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://www.hello-algo.com/en/index.assets/animation.gif" width="396">
|
<img src="https://www.hello-algo.com/en/index.assets/animation.gif" width="389">
|
||||||
<img src="https://www.hello-algo.com/en/index.assets/running_code.gif" width="396">
|
<img src="https://www.hello-algo.com/en/index.assets/running_code.gif" width="389">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@ -35,13 +31,21 @@
|
|||||||
<img src="https://img.shields.io/badge/Dart-snow?logo=dart&logoColor=0175C2">
|
<img src="https://img.shields.io/badge/Dart-snow?logo=dart&logoColor=0175C2">
|
||||||
<img src="https://img.shields.io/badge/Rust-snow?logo=rust&logoColor=000000">
|
<img src="https://img.shields.io/badge/Rust-snow?logo=rust&logoColor=000000">
|
||||||
<img src="https://img.shields.io/badge/C-snow?logo=c&logoColor=A8B9CC">
|
<img src="https://img.shields.io/badge/C-snow?logo=c&logoColor=A8B9CC">
|
||||||
|
<img src="https://img.shields.io/badge/Kotlin-snow?logo=kotlin&logoColor=7F52FF">
|
||||||
<img src="https://img.shields.io/badge/Zig-snow?logo=zig&logoColor=F7A41D">
|
<img src="https://img.shields.io/badge/Zig-snow?logo=zig&logoColor=F7A41D">
|
||||||
<img src="https://img.shields.io/badge/Stay%20Tuned-snow">
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
> [!Important]
|
<p align="center">
|
||||||
>
|
<a href="https://github.com/krahets/hello-algo">
|
||||||
> We are working on Chinese-to-English translation. For more information please see [#914](https://github.com/krahets/hello-algo/issues/914).
|
简体中文
|
||||||
|
</a>
|
||||||
|
|
|
||||||
|
<a href="https://github.com/krahets/hello-algo/blob/main/zh-hant/README.md">
|
||||||
|
繁體中文
|
||||||
|
</a>
|
||||||
|
|
|
||||||
|
English
|
||||||
|
</p>
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
@ -65,6 +69,10 @@ If you find this book helpful, please give it a Star :star: to support us, thank
|
|||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
|
|
||||||
|
> [!Important]
|
||||||
|
>
|
||||||
|
> We are working on Chinese-to-English translation. For more information please see [#914](https://github.com/krahets/hello-algo/issues/914).
|
||||||
|
|
||||||
This open-source book is continuously being updated, and we welcome your participation in this project to provide better learning content for readers.
|
This open-source book is continuously being updated, and we welcome your participation in this project to provide better learning content for readers.
|
||||||
|
|
||||||
- [Content Correction](https://www.hello-algo.com/en/chapter_appendix/contribution/): Please help us correct or point out mistakes in the comments section such as grammatical errors, missing content, ambiguities, invalid links, or code bugs.
|
- [Content Correction](https://www.hello-algo.com/en/chapter_appendix/contribution/): Please help us correct or point out mistakes in the comments section such as grammatical errors, missing content, ambiguities, invalid links, or code bugs.
|
||||||
|
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 126 KiB After Width: | Height: | Size: 125 KiB |
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 127 KiB |
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 95 KiB |
Before Width: | Height: | Size: 142 KiB After Width: | Height: | Size: 142 KiB |
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 103 KiB |
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 163 KiB |
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 84 KiB |
Before Width: | Height: | Size: 136 KiB After Width: | Height: | Size: 136 KiB |
Before Width: | Height: | Size: 137 KiB After Width: | Height: | Size: 136 KiB |
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 110 KiB |
BIN
en/docs/assets/covers/chapter_hello_algo.jpg
Normal file
After Width: | Height: | Size: 142 KiB |
Before Width: | Height: | Size: 138 KiB After Width: | Height: | Size: 136 KiB |
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 119 KiB |
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 129 KiB |
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 91 KiB |
Before Width: | Height: | Size: 104 KiB After Width: | Height: | Size: 104 KiB |
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 118 KiB |
@ -45,7 +45,7 @@ hide:
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="admonition example" style="max-width: 800px;margin: 0 auto;">
|
<div class="admonition example" style="max-width: 800px;margin: 0 auto;">
|
||||||
<p class="admonition-title">The English edition is brewing...</p>
|
<p class="admonition-title">The English version is brewing...</p>
|
||||||
<p>Feel free to engage in Chinese-to-English translation and pull request review! For guidelines, please see <a href="https://github.com/krahets/hello-algo/issues/914">#914</a>.</p>
|
<p>Feel free to engage in Chinese-to-English translation and pull request review! For guidelines, please see <a href="https://github.com/krahets/hello-algo/issues/914">#914</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -3,8 +3,10 @@
|
|||||||
{% block announce %}
|
{% block announce %}
|
||||||
{% if config.theme.language == 'zh' %}
|
{% if config.theme.language == 'zh' %}
|
||||||
{% set announcements = '纸质书已发布,详情请见<a href="/chapter_paperbook/">这里</a>' %}
|
{% set announcements = '纸质书已发布,详情请见<a href="/chapter_paperbook/">这里</a>' %}
|
||||||
|
{% if config.theme.language == 'zh-Hant' %}
|
||||||
|
{% set announcements = '紙質書(簡體中文版)已發行,詳情請見<a href="/chapter_paperbook/">這裡</a>' %}
|
||||||
{% elif config.theme.language == 'en' %}
|
{% elif config.theme.language == 'en' %}
|
||||||
{% set announcements = 'The paper book (Chinese edition) published. Please visit <a href="/chapter_paperbook/">this link</a> for more details.' %}
|
{% set announcements = 'The paper book (Chinese version) published. Please visit <a href="/chapter_paperbook/">this link</a> for more details.' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="banner-svg">
|
<div class="banner-svg">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg"
|
<svg xmlns="http://www.w3.org/2000/svg"
|
||||||
|
@ -4,23 +4,19 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://readme-typing-svg.demolab.com?font=Noto+Sans+SC&weight=500&duration=3500&pause=2000&color=21C8B8¢er=true&vCenter=true&random=false&width=200&lines=Hello%2C+%E7%AE%97%E6%B3%95+!" alt="hello-algo-typing-svg" />
|
<img style="height: 60px;" src="https://readme-typing-svg.demolab.com/?font=Noto+Sans+SC&weight=400&duration=3500&pause=2000&color=21C8B8¢er=true&vCenter=true&random=false&width=200&lines=Hello%2C+%E6%BC%94%E7%AE%97%E6%B3%95+!" alt="hello-algo-typing-svg" />
|
||||||
</br>
|
</br>
|
||||||
動畫圖解、一鍵執行的資料結構與演算法教程
|
動畫圖解、一鍵執行的資料結構與演算法教程
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://www.hello-algo.com/">
|
<a href="https://www.hello-algo.com/zh-hant/">
|
||||||
<img src="https://www.hello-algo.com/index.assets/btn_read_online_dark.svg" width="145"></a>
|
<img src="https://www.hello-algo.com/zh-hant/index.assets/btn_read_online_dark.svg" width="145"></a>
|
||||||
<a href="https://github.com/krahets/hello-algo/releases">
|
|
||||||
<img src="https://www.hello-algo.com/index.assets/btn_download_pdf_dark.svg" width="145"></a>
|
|
||||||
<a href="https://github.com/krahets/hello-algo/blob/main/en/README.md">
|
|
||||||
<img src="https://www.hello-algo.com/index.assets/btn_english_edition_dark.svg" width="145"></a>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://www.hello-algo.com/index.assets/animation.gif" width="396">
|
<img src="https://www.hello-algo.com/index.assets/animation.gif" width="389">
|
||||||
<img src="https://www.hello-algo.com/index.assets/running_code.gif" width="396">
|
<img src="https://www.hello-algo.com/index.assets/running_code.gif" width="389">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@ -35,8 +31,20 @@
|
|||||||
<img src="https://img.shields.io/badge/Dart-snow?logo=dart&logoColor=0175C2">
|
<img src="https://img.shields.io/badge/Dart-snow?logo=dart&logoColor=0175C2">
|
||||||
<img src="https://img.shields.io/badge/Rust-snow?logo=rust&logoColor=000000">
|
<img src="https://img.shields.io/badge/Rust-snow?logo=rust&logoColor=000000">
|
||||||
<img src="https://img.shields.io/badge/C-snow?logo=c&logoColor=A8B9CC">
|
<img src="https://img.shields.io/badge/C-snow?logo=c&logoColor=A8B9CC">
|
||||||
|
<img src="https://img.shields.io/badge/Kotlin-snow?logo=kotlin&logoColor=7F52FF">
|
||||||
<img src="https://img.shields.io/badge/Zig-snow?logo=zig&logoColor=F7A41D">
|
<img src="https://img.shields.io/badge/Zig-snow?logo=zig&logoColor=F7A41D">
|
||||||
<img src="https://img.shields.io/badge/Stay%20Tuned-snow">
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://github.com/krahets/hello-algo">
|
||||||
|
简体中文
|
||||||
|
</a>
|
||||||
|
|
|
||||||
|
繁體中文
|
||||||
|
|
|
||||||
|
<a href="https://github.com/krahets/hello-algo/blob/main/en/README.md">
|
||||||
|
English
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## 關於本書
|
## 關於本書
|
||||||
@ -61,6 +69,10 @@
|
|||||||
|
|
||||||
## 貢獻
|
## 貢獻
|
||||||
|
|
||||||
|
> [!Important]
|
||||||
|
>
|
||||||
|
> 歡迎您於 [#1171](https://github.com/krahets/hello-algo/issues/1171) 為繁體中文版勘誤。
|
||||||
|
|
||||||
本開源書仍在持續更新之中,歡迎您參與本專案,一同為讀者提供更優質的學習內容。
|
本開源書仍在持續更新之中,歡迎您參與本專案,一同為讀者提供更優質的學習內容。
|
||||||
|
|
||||||
- [內容修正](https://www.hello-algo.com/chapter_appendix/contribution/):請您協助修正或在評論區指出語法錯誤、內容缺失、文字歧義、無效連結或程式碼 bug 等問題。
|
- [內容修正](https://www.hello-algo.com/chapter_appendix/contribution/):請您協助修正或在評論區指出語法錯誤、內容缺失、文字歧義、無效連結或程式碼 bug 等問題。
|
||||||
|
@ -106,7 +106,7 @@ def log_recur(n)
|
|||||||
log_recur(n / 2) + 1
|
log_recur(n / 2) + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
### 線性對數階
|
### 線性對數階 ###
|
||||||
def linear_log_recur(n)
|
def linear_log_recur(n)
|
||||||
return 1 unless n > 1
|
return 1 unless n > 1
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ Author: Xuan Khoa Tu Nguyen (ngxktuzkai2000@gmail.com)
|
|||||||
=end
|
=end
|
||||||
|
|
||||||
### 生成一個陣列,元素為: 1, 2, ..., n ,順序被打亂 ###
|
### 生成一個陣列,元素為: 1, 2, ..., n ,順序被打亂 ###
|
||||||
def random_number(n)
|
def random_numbers(n)
|
||||||
# 生成陣列 nums =: 1, 2, 3, ..., n
|
# 生成陣列 nums =: 1, 2, 3, ..., n
|
||||||
nums = Array.new(n) { |i| i + 1 }
|
nums = Array.new(n) { |i| i + 1 }
|
||||||
# 隨機打亂陣列元素
|
# 隨機打亂陣列元素
|
||||||
@ -27,7 +27,7 @@ end
|
|||||||
|
|
||||||
for i in 0...10
|
for i in 0...10
|
||||||
n = 100
|
n = 100
|
||||||
nums = random_number(n)
|
nums = random_numbers(n)
|
||||||
index = find_one(nums)
|
index = find_one(nums)
|
||||||
puts "\n陣列 [ 1, 2, ..., n ] 被打亂後 = #{nums}"
|
puts "\n陣列 [ 1, 2, ..., n ] 被打亂後 = #{nums}"
|
||||||
puts "數字 1 的索引為 #{index}"
|
puts "數字 1 的索引為 #{index}"
|
||||||
|
@ -27,18 +27,18 @@
|
|||||||
| big-$O$ notation | 大 $O$ 记号 | 大 $O$ 記號 |
|
| big-$O$ notation | 大 $O$ 记号 | 大 $O$ 記號 |
|
||||||
| asymptotic upper bound | 渐近上界 | 漸近上界 |
|
| asymptotic upper bound | 渐近上界 | 漸近上界 |
|
||||||
| sign-magnitude | 原码 | 原碼 |
|
| sign-magnitude | 原码 | 原碼 |
|
||||||
| 1’s complement | 反码 | 反碼 |
|
| 1’s complement | 反码 | 一補數 |
|
||||||
| 2’s complement | 补码 | 補碼 |
|
| 2’s complement | 补码 | 二補數 |
|
||||||
| array | 数组 | 陣列 |
|
| array | 数组 | 陣列 |
|
||||||
| index | 索引 | 索引 |
|
| index | 索引 | 索引 |
|
||||||
| linked list | 链表 | 鏈結串列 |
|
| linked list | 链表 | 鏈結串列 |
|
||||||
| linked list node, list node | 链表节点 | 鏈結串列節點 |
|
| linked list node, list node | 链表节点 | 鏈結串列節點 |
|
||||||
| head node | 头节点 | 頭節點 |
|
| head node | 头节点 | 頭節點 |
|
||||||
| tail node | 尾节点 | 尾節點 |
|
| tail node | 尾节点 | 尾節點 |
|
||||||
| list | 列表 | 列表 |
|
| list | 列表 | 串列 |
|
||||||
| dynamic array | 动态数组 | 動態陣列 |
|
| dynamic array | 动态数组 | 動態陣列 |
|
||||||
| hard disk | 硬盘 | 硬碟 |
|
| hard disk | 硬盘 | 硬碟 |
|
||||||
| random-access memory (RAM) | 内存 | 內存 |
|
| random-access memory (RAM) | 内存 | 記憶體 |
|
||||||
| cache memory | 缓存 | 快取 |
|
| cache memory | 缓存 | 快取 |
|
||||||
| cache miss | 缓存未命中 | 快取未命中 |
|
| cache miss | 缓存未命中 | 快取未命中 |
|
||||||
| cache hit rate | 缓存命中率 | 快取命中率 |
|
| cache hit rate | 缓存命中率 | 快取命中率 |
|
||||||
@ -106,7 +106,7 @@
|
|||||||
| adjacency list | 邻接表 | 鄰接表 |
|
| adjacency list | 邻接表 | 鄰接表 |
|
||||||
| breadth-first search | 广度优先搜索 | 廣度優先搜尋 |
|
| breadth-first search | 广度优先搜索 | 廣度優先搜尋 |
|
||||||
| depth-first search | 深度优先搜索 | 深度優先搜尋 |
|
| depth-first search | 深度优先搜索 | 深度優先搜尋 |
|
||||||
| binary search | 二分查找 | 二分查找 |
|
| binary search | 二分查找 | 二分搜尋 |
|
||||||
| searching algorithm | 搜索算法 | 搜尋演算法 |
|
| searching algorithm | 搜索算法 | 搜尋演算法 |
|
||||||
| sorting algorithm | 排序算法 | 排序演算法 |
|
| sorting algorithm | 排序算法 | 排序演算法 |
|
||||||
| selection sort | 选择排序 | 選擇排序 |
|
| selection sort | 选择排序 | 選擇排序 |
|
||||||
@ -130,7 +130,7 @@
|
|||||||
| $n$-queens problem | $n$ 皇后问题 | $n$ 皇后問題 |
|
| $n$-queens problem | $n$ 皇后问题 | $n$ 皇后問題 |
|
||||||
| dynamic programming | 动态规划 | 動態規劃 |
|
| dynamic programming | 动态规划 | 動態規劃 |
|
||||||
| initial state | 初始状态 | 初始狀態 |
|
| initial state | 初始状态 | 初始狀態 |
|
||||||
| state-trasition equation | 状态转移方程 | 狀態轉移方程 |
|
| state-transition equation | 状态转移方程 | 狀態轉移方程 |
|
||||||
| knapsack problem | 背包问题 | 背包問題 |
|
| knapsack problem | 背包问题 | 背包問題 |
|
||||||
| edit distance problem | 编辑距离问题 | 編輯距離問題 |
|
| edit distance problem | 编辑距离问题 | 編輯距離問題 |
|
||||||
| greedy algorithm | 贪心算法 | 貪婪演算法 |
|
| greedy algorithm | 贪心算法 | 貪婪演算法 |
|
||||||
|
@ -563,13 +563,13 @@
|
|||||||
// 執行某些操作
|
// 執行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 迴圈 O(1) */
|
/* 迴圈的空間複雜度為 O(1) */
|
||||||
void loop(int n) {
|
void loop(int n) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 遞迴 O(n) */
|
/* 遞迴的空間複雜度為 O(n) */
|
||||||
void recur(int n) {
|
void recur(int n) {
|
||||||
if (n == 1) return;
|
if (n == 1) return;
|
||||||
return recur(n - 1);
|
return recur(n - 1);
|
||||||
@ -583,13 +583,13 @@
|
|||||||
// 執行某些操作
|
// 執行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 迴圈 O(1) */
|
/* 迴圈的空間複雜度為 O(1) */
|
||||||
void loop(int n) {
|
void loop(int n) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
function();
|
function();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 遞迴 O(n) */
|
/* 遞迴的空間複雜度為 O(n) */
|
||||||
void recur(int n) {
|
void recur(int n) {
|
||||||
if (n == 1) return;
|
if (n == 1) return;
|
||||||
return recur(n - 1);
|
return recur(n - 1);
|
||||||
@ -603,13 +603,13 @@
|
|||||||
// 執行某些操作
|
// 執行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 迴圈 O(1) */
|
/* 迴圈的空間複雜度為 O(1) */
|
||||||
void Loop(int n) {
|
void Loop(int n) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
Function();
|
Function();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 遞迴 O(n) */
|
/* 遞迴的空間複雜度為 O(n) */
|
||||||
int Recur(int n) {
|
int Recur(int n) {
|
||||||
if (n == 1) return 1;
|
if (n == 1) return 1;
|
||||||
return Recur(n - 1);
|
return Recur(n - 1);
|
||||||
@ -624,14 +624,14 @@
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 迴圈 O(1) */
|
/* 迴圈的空間複雜度為 O(1) */
|
||||||
func loop(n int) {
|
func loop(n int) {
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
function()
|
function()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 遞迴 O(n) */
|
/* 遞迴的空間複雜度為 O(n) */
|
||||||
func recur(n int) {
|
func recur(n int) {
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
return
|
return
|
||||||
@ -649,14 +649,14 @@
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 迴圈 O(1) */
|
/* 迴圈的空間複雜度為 O(1) */
|
||||||
func loop(n: Int) {
|
func loop(n: Int) {
|
||||||
for _ in 0 ..< n {
|
for _ in 0 ..< n {
|
||||||
function()
|
function()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 遞迴 O(n) */
|
/* 遞迴的空間複雜度為 O(n) */
|
||||||
func recur(n: Int) {
|
func recur(n: Int) {
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
return
|
return
|
||||||
@ -672,13 +672,13 @@
|
|||||||
// 執行某些操作
|
// 執行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 迴圈 O(1) */
|
/* 迴圈的空間複雜度為 O(1) */
|
||||||
function loop(n) {
|
function loop(n) {
|
||||||
for (let i = 0; i < n; i++) {
|
for (let i = 0; i < n; i++) {
|
||||||
constFunc();
|
constFunc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 遞迴 O(n) */
|
/* 遞迴的空間複雜度為 O(n) */
|
||||||
function recur(n) {
|
function recur(n) {
|
||||||
if (n === 1) return;
|
if (n === 1) return;
|
||||||
return recur(n - 1);
|
return recur(n - 1);
|
||||||
@ -692,13 +692,13 @@
|
|||||||
// 執行某些操作
|
// 執行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 迴圈 O(1) */
|
/* 迴圈的空間複雜度為 O(1) */
|
||||||
function loop(n: number): void {
|
function loop(n: number): void {
|
||||||
for (let i = 0; i < n; i++) {
|
for (let i = 0; i < n; i++) {
|
||||||
constFunc();
|
constFunc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 遞迴 O(n) */
|
/* 遞迴的空間複雜度為 O(n) */
|
||||||
function recur(n: number): void {
|
function recur(n: number): void {
|
||||||
if (n === 1) return;
|
if (n === 1) return;
|
||||||
return recur(n - 1);
|
return recur(n - 1);
|
||||||
@ -712,13 +712,13 @@
|
|||||||
// 執行某些操作
|
// 執行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 迴圈 O(1) */
|
/* 迴圈的空間複雜度為 O(1) */
|
||||||
void loop(int n) {
|
void loop(int n) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
function();
|
function();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 遞迴 O(n) */
|
/* 遞迴的空間複雜度為 O(n) */
|
||||||
void recur(int n) {
|
void recur(int n) {
|
||||||
if (n == 1) return;
|
if (n == 1) return;
|
||||||
return recur(n - 1);
|
return recur(n - 1);
|
||||||
@ -732,13 +732,13 @@
|
|||||||
// 執行某些操作
|
// 執行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 迴圈 O(1) */
|
/* 迴圈的空間複雜度為 O(1) */
|
||||||
fn loop(n: i32) {
|
fn loop(n: i32) {
|
||||||
for i in 0..n {
|
for i in 0..n {
|
||||||
function();
|
function();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 遞迴 O(n) */
|
/* 遞迴的空間複雜度為 O(n) */
|
||||||
fn recur(n: i32) {
|
fn recur(n: i32) {
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
return;
|
return;
|
||||||
@ -754,13 +754,13 @@
|
|||||||
// 執行某些操作
|
// 執行某些操作
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* 迴圈 O(1) */
|
/* 迴圈的空間複雜度為 O(1) */
|
||||||
void loop(int n) {
|
void loop(int n) {
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 遞迴 O(n) */
|
/* 遞迴的空間複雜度為 O(n) */
|
||||||
void recur(int n) {
|
void recur(int n) {
|
||||||
if (n == 1) return;
|
if (n == 1) return;
|
||||||
return recur(n - 1);
|
return recur(n - 1);
|
||||||
@ -774,13 +774,13 @@
|
|||||||
// 執行某些操作
|
// 執行某些操作
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
/* 迴圈 O(1) */
|
/* 迴圈的空間複雜度為 O(1) */
|
||||||
fun loop(n: Int) {
|
fun loop(n: Int) {
|
||||||
for (i in 0..<n) {
|
for (i in 0..<n) {
|
||||||
function()
|
function()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 遞迴 O(n) */
|
/* 遞迴的空間複雜度為 O(n) */
|
||||||
fun recur(n: Int) {
|
fun recur(n: Int) {
|
||||||
if (n == 1) return
|
if (n == 1) return
|
||||||
return recur(n - 1)
|
return recur(n - 1)
|
||||||
|
@ -743,7 +743,7 @@ $$
|
|||||||
|
|
||||||
$T(n)$ 是一次函式,說明其執行時間的增長趨勢是線性的,因此它的時間複雜度是線性階。
|
$T(n)$ 是一次函式,說明其執行時間的增長趨勢是線性的,因此它的時間複雜度是線性階。
|
||||||
|
|
||||||
我們將線性階的時間複雜度記為 $O(n)$ ,這個數學符號稱為<u>大($O$ 記號 big-$O$ notation)</u>,表示函式 $T(n)$ 的<u>漸近上界(asymptotic upper bound)</u>。
|
我們將線性階的時間複雜度記為 $O(n)$ ,這個數學符號稱為<u>大 $O$ 記號(big-$O$ notation)</u>,表示函式 $T(n)$ 的<u>漸近上界(asymptotic upper bound)</u>。
|
||||||
|
|
||||||
時間複雜度分析本質上是計算“操作數量 $T(n)$”的漸近上界,它具有明確的數學定義。
|
時間複雜度分析本質上是計算“操作數量 $T(n)$”的漸近上界,它具有明確的數學定義。
|
||||||
|
|
||||||
|