mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-14 02:10:37 +08:00
Release Rust code to documents. (#656)
This commit is contained in:
@@ -80,6 +80,12 @@
|
||||
[class]{}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
|
||||
```rust title="binary_tree_bfs.rs"
|
||||
[class]{}-[func]{level_order}
|
||||
```
|
||||
|
||||
**时间复杂度**:所有节点被访问一次,使用 $O(n)$ 时间,其中 $n$ 为节点数量。
|
||||
|
||||
**空间复杂度**:在最差情况下,即满二叉树时,遍历到最底层之前,队列中最多同时存在 $\frac{n + 1}{2}$ 个节点,占用 $O(n)$ 空间。
|
||||
@@ -204,6 +210,16 @@
|
||||
[class]{}-[func]{postOrder}
|
||||
```
|
||||
|
||||
=== "Rust"
|
||||
|
||||
```rust title="binary_tree_dfs.rs"
|
||||
[class]{}-[func]{pre_order}
|
||||
|
||||
[class]{}-[func]{in_order}
|
||||
|
||||
[class]{}-[func]{post_order}
|
||||
```
|
||||
|
||||
**时间复杂度**:所有节点被访问一次,使用 $O(n)$ 时间,其中 $n$ 为节点数量。
|
||||
|
||||
**空间复杂度**:在最差情况下,即树退化为链表时,递归深度达到 $n$ ,系统占用 $O(n)$ 栈帧空间。
|
||||
|
||||
Reference in New Issue
Block a user