mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-09 22:16:06 +00:00
Release Rust code to documents. (#656)
This commit is contained in:
@@ -127,3 +127,11 @@
|
||||
|
||||
[class]{}-[func]{binarySearch}
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
|
||||
```rust title="binary_search_recur.rs"
|
||||
[class]{}-[func]{dfs}
|
||||
|
||||
[class]{}-[func]{binary_search}
|
||||
```
|
||||
|
||||
@@ -147,6 +147,14 @@
|
||||
[class]{}-[func]{buildTree}
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
|
||||
```rust title="build_tree.rs"
|
||||
[class]{}-[func]{dfs}
|
||||
|
||||
[class]{}-[func]{build_tree}
|
||||
```
|
||||
|
||||
下图展示了构建二叉树的递归过程,各个节点是在向下“递”的过程中建立的,而各条边(即引用)是在向上“归”的过程中建立的。
|
||||
|
||||
=== "<1>"
|
||||
|
||||
@@ -192,6 +192,16 @@
|
||||
[class]{}-[func]{hanota}
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
|
||||
```rust title="hanota.rs"
|
||||
[class]{}-[func]{move_pan}
|
||||
|
||||
[class]{}-[func]{dfs}
|
||||
|
||||
[class]{}-[func]{hanota}
|
||||
```
|
||||
|
||||
如下图所示,汉诺塔问题形成一个高度为 $n$ 的递归树,每个节点代表一个子问题、对应一个开启的 `dfs()` 函数,**因此时间复杂度为 $O(2^n)$ ,空间复杂度为 $O(n)$** 。
|
||||
|
||||

|
||||
|
||||
Reference in New Issue
Block a user