Number the H1 and H2 headings.

This commit is contained in:
Yudong Jin
2023-01-31 03:37:50 +08:00
parent dbbc1adc4f
commit eb0afc98ec
44 changed files with 263 additions and 257 deletions

View File

@ -2,11 +2,11 @@
comments: true
---
# 线性查找
# 10.1. 线性查找
「线性查找 Linear Search」是一种最基础的查找方法其从数据结构的一端开始依次访问每个元素直到另一端后停止。
## 算法实现
## 10.1.1. 算法实现
线性查找实质上就是遍历数据结构 + 判断条件。比如,我们想要在数组 `nums` 中查找目标元素 `target` 的对应索引,那么可以在数组中进行线性查找。
@ -297,13 +297,13 @@ comments: true
}
```
## 复杂度分析
## 10.1.2. 复杂度分析
**时间复杂度 $O(n)$** :其中 $n$ 为数组或链表长度。
**空间复杂度 $O(1)$** :无需使用额外空间。
## 优点与缺点
## 10.1.3. 优点与缺点
**线性查找的通用性极佳**。由于线性查找是依次访问元素的,即没有跳跃访问元素,因此数组或链表皆适用。