mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-29 23:23:43 +00:00
Update 算法 - 其它.md
重新绘制汉诺塔和哈夫曼树的配图,补充参考资料。
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 61 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 61 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 120 KiB |
+11
-6
@@ -1,7 +1,7 @@
|
||||
# 算法 - 其它
|
||||
## 汉诺塔
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/69d6c38d-1dec-4f72-ae60-60dbc10e9d15.png" width="300"/> </div><br>
|
||||
<div align="center"> <img src="pics/hanoi-start.png" width="460px"/> </div><br>
|
||||
|
||||
有三个柱子,分别为 from、buffer、to。需要将 from 上的圆盘全部移动到 to 上,并且要保证小圆盘始终在大圆盘上。
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
|
||||
① 将 n-1 个圆盘从 from -\> buffer
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/f9240aa1-8d48-4959-b28a-7ca45c3e4d91.png" width="300"/> </div><br>
|
||||
<div align="center"> <img src="pics/hanoi-step1.png" width="460px"/> </div><br>
|
||||
|
||||
② 将 1 个圆盘从 from -\> to
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/f579cab0-3d49-4d00-8e14-e9e1669d0f9f.png" width="300"/> </div><br>
|
||||
<div align="center"> <img src="pics/hanoi-step2.png" width="460px"/> </div><br>
|
||||
|
||||
③ 将 n-1 个圆盘从 buffer -\> to
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/d02f74dd-8e33-4f3c-bf29-53203a06695a.png" width="300"/> </div><br>
|
||||
<div align="center"> <img src="pics/hanoi-step3.png" width="460px"/> </div><br>
|
||||
|
||||
如果只有一个圆盘,那么只需要进行一次移动操作。
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Hanoi {
|
||||
}
|
||||
```
|
||||
|
||||
```html
|
||||
```text
|
||||
from H1 to H3
|
||||
from H1 to H2
|
||||
from H3 to H2
|
||||
@@ -68,7 +68,7 @@ from H1 to H3
|
||||
|
||||
生成编码时,从根节点出发,向左遍历则添加二进制位 0,向右则添加二进制位 1,直到遍历到叶子节点,叶子节点代表的字符的编码就是这个路径编码。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/8edc5164-810b-4cc5-bda8-2a2c98556377.jpg" width="300"/> </div><br>
|
||||
<div align="center"> <img src="pics/huffman-tree.png" width="620px"/> </div><br>
|
||||
|
||||
```java
|
||||
public class Huffman {
|
||||
@@ -127,3 +127,8 @@ public class Huffman {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 参考资料
|
||||
|
||||
- Sedgewick R, Wayne K. 算法(第 4 版)[M]. 人民邮电出版社, 2012.
|
||||
- [Algorithms, 4th Edition](https://algs4.cs.princeton.edu/home/)
|
||||
|
||||
Reference in New Issue
Block a user