auto commit
This commit is contained in:
parent
e9d55fe415
commit
3a264ff9b8
11
notes/算法.md
11
notes/算法.md
|
@ -901,7 +901,7 @@ public static Comparable select(Comparable[] a, int k) {
|
|||
|
||||
## 二分查找实现有序符号表
|
||||
|
||||
使用一对平行数组,一个存储键一个存储值。其中键的数组为 Comparable 数组,值的数组为 Object 数组。
|
||||
使用一对平行数组,一个存储键一个存储值。
|
||||
|
||||
rank() 方法至关重要,当键在表中时,它能够知道该键的位置;当键不在表中时,它也能知道在何处插入新键。
|
||||
|
||||
|
@ -976,7 +976,7 @@ public class BinarySearchST<Key extends Comparable<Key>, Value> {
|
|||
|
||||
BST 有一个重要性质,就是它的中序遍历结果递增排序。
|
||||
|
||||
<div align="center"> <img src="../pics//05e41947-3cbc-4f02-a428-96765ec916ff.png" width="200"/> </div><br>
|
||||
<div align="center"> <img src="../pics//fbe54203-c005-48f0-8883-b05e564a3173.png" width="200"/> </div><br>
|
||||
|
||||
基本数据结构:
|
||||
|
||||
|
@ -1017,8 +1017,6 @@ public class BST<Key extends Comparable<Key>, Value> {
|
|||
- 如果被查找的键和根节点的键相等,查找命中;
|
||||
- 否则递归地在子树中查找:如果被查找的键较小就在左子树中查找,较大就在右子树中查找。
|
||||
|
||||
BST 的查找操作每次递归都会让区间减少一半,和二分查找类似,因此查找的复杂度为 O(logN)。
|
||||
|
||||
```java
|
||||
public Value get(Key key) {
|
||||
return get(root, key);
|
||||
|
@ -1125,7 +1123,7 @@ private Node min(Node x) {
|
|||
|
||||
令指向最小节点的链接指向最小节点的右子树。
|
||||
|
||||
<div align="center"> <img src="../pics//26020e1a-06ab-4114-a6b3-e428de690c7e.png" width="500"/> </div><br>
|
||||
<div align="center"> <img src="../pics//dd15a984-e977-4644-b127-708cddb8ca99.png" width="500"/> </div><br>
|
||||
|
||||
```java
|
||||
public void deleteMin() {
|
||||
|
@ -1144,7 +1142,8 @@ public Node deleteMin(Node x) {
|
|||
- 如果待删除的节点只有一个子树,那么只需要让指向待删除节点的链接指向唯一的子树即可;
|
||||
- 否则,让右子树的最小节点替换该节点。
|
||||
|
||||
<div align="center"> <img src="../pics//3290673d-edab-4678-8b2e-f18e0f6b7fc1.png" width="400"/> </div><br>
|
||||
<div align="center"> <img src="../pics//fa568fac-ac58-48dd-a9bb-23b3065bf2dc.png" width="400"/> </div><br>
|
||||
|
||||
|
||||
```java
|
||||
public void delete(Key key) {
|
||||
|
|
BIN
pics/dd15a984-e977-4644-b127-708cddb8ca99.png
Normal file
BIN
pics/dd15a984-e977-4644-b127-708cddb8ca99.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
BIN
pics/fa568fac-ac58-48dd-a9bb-23b3065bf2dc.png
Normal file
BIN
pics/fa568fac-ac58-48dd-a9bb-23b3065bf2dc.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
pics/fbe54203-c005-48f0-8883-b05e564a3173.png
Normal file
BIN
pics/fbe54203-c005-48f0-8883-b05e564a3173.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.0 KiB |
Loading…
Reference in New Issue
Block a user