mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-10 14:36:06 +00:00
Sort the coding languages by applications. (#721)
This commit is contained in:
@@ -16,10 +16,10 @@
|
||||
|
||||
广度优先遍历通常借助“队列”来实现。队列遵循“先进先出”的规则,而广度优先遍历则遵循“逐层推进”的规则,两者背后的思想是一致的。
|
||||
|
||||
=== "Java"
|
||||
=== "Python"
|
||||
|
||||
```java title="binary_tree_bfs.java"
|
||||
[class]{binary_tree_bfs}-[func]{levelOrder}
|
||||
```python title="binary_tree_bfs.py"
|
||||
[class]{}-[func]{level_order}
|
||||
```
|
||||
|
||||
=== "C++"
|
||||
@@ -28,10 +28,16 @@
|
||||
[class]{}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
=== "Python"
|
||||
=== "Java"
|
||||
|
||||
```python title="binary_tree_bfs.py"
|
||||
[class]{}-[func]{level_order}
|
||||
```java title="binary_tree_bfs.java"
|
||||
[class]{binary_tree_bfs}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="binary_tree_bfs.cs"
|
||||
[class]{binary_tree_bfs}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
=== "Go"
|
||||
@@ -40,6 +46,12 @@
|
||||
[class]{}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="binary_tree_bfs.swift"
|
||||
[class]{}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
=== "JS"
|
||||
|
||||
```javascript title="binary_tree_bfs.js"
|
||||
@@ -52,30 +64,6 @@
|
||||
[class]{}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="binary_tree_bfs.c"
|
||||
[class]{}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="binary_tree_bfs.cs"
|
||||
[class]{binary_tree_bfs}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="binary_tree_bfs.swift"
|
||||
[class]{}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="binary_tree_bfs.zig"
|
||||
[class]{}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
=== "Dart"
|
||||
|
||||
```dart title="binary_tree_bfs.dart"
|
||||
@@ -88,6 +76,18 @@
|
||||
[class]{}-[func]{level_order}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="binary_tree_bfs.c"
|
||||
[class]{}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="binary_tree_bfs.zig"
|
||||
[class]{}-[func]{levelOrder}
|
||||
```
|
||||
|
||||
### 复杂度分析
|
||||
|
||||
- **时间复杂度 $O(n)$** :所有节点被访问一次,使用 $O(n)$ 时间,其中 $n$ 为节点数量。
|
||||
@@ -105,14 +105,14 @@
|
||||
|
||||
深度优先搜索通常基于递归实现:
|
||||
|
||||
=== "Java"
|
||||
=== "Python"
|
||||
|
||||
```java title="binary_tree_dfs.java"
|
||||
[class]{binary_tree_dfs}-[func]{preOrder}
|
||||
```python title="binary_tree_dfs.py"
|
||||
[class]{}-[func]{pre_order}
|
||||
|
||||
[class]{binary_tree_dfs}-[func]{inOrder}
|
||||
[class]{}-[func]{in_order}
|
||||
|
||||
[class]{binary_tree_dfs}-[func]{postOrder}
|
||||
[class]{}-[func]{post_order}
|
||||
```
|
||||
|
||||
=== "C++"
|
||||
@@ -125,14 +125,24 @@
|
||||
[class]{}-[func]{postOrder}
|
||||
```
|
||||
|
||||
=== "Python"
|
||||
=== "Java"
|
||||
|
||||
```python title="binary_tree_dfs.py"
|
||||
[class]{}-[func]{pre_order}
|
||||
```java title="binary_tree_dfs.java"
|
||||
[class]{binary_tree_dfs}-[func]{preOrder}
|
||||
|
||||
[class]{}-[func]{in_order}
|
||||
[class]{binary_tree_dfs}-[func]{inOrder}
|
||||
|
||||
[class]{}-[func]{post_order}
|
||||
[class]{binary_tree_dfs}-[func]{postOrder}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="binary_tree_dfs.cs"
|
||||
[class]{binary_tree_dfs}-[func]{preOrder}
|
||||
|
||||
[class]{binary_tree_dfs}-[func]{inOrder}
|
||||
|
||||
[class]{binary_tree_dfs}-[func]{postOrder}
|
||||
```
|
||||
|
||||
=== "Go"
|
||||
@@ -145,6 +155,16 @@
|
||||
[class]{}-[func]{postOrder}
|
||||
```
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="binary_tree_dfs.swift"
|
||||
[class]{}-[func]{preOrder}
|
||||
|
||||
[class]{}-[func]{inOrder}
|
||||
|
||||
[class]{}-[func]{postOrder}
|
||||
```
|
||||
|
||||
=== "JS"
|
||||
|
||||
```javascript title="binary_tree_dfs.js"
|
||||
@@ -165,46 +185,6 @@
|
||||
[class]{}-[func]{postOrder}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="binary_tree_dfs.c"
|
||||
[class]{}-[func]{preOrder}
|
||||
|
||||
[class]{}-[func]{inOrder}
|
||||
|
||||
[class]{}-[func]{postOrder}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
|
||||
```csharp title="binary_tree_dfs.cs"
|
||||
[class]{binary_tree_dfs}-[func]{preOrder}
|
||||
|
||||
[class]{binary_tree_dfs}-[func]{inOrder}
|
||||
|
||||
[class]{binary_tree_dfs}-[func]{postOrder}
|
||||
```
|
||||
|
||||
=== "Swift"
|
||||
|
||||
```swift title="binary_tree_dfs.swift"
|
||||
[class]{}-[func]{preOrder}
|
||||
|
||||
[class]{}-[func]{inOrder}
|
||||
|
||||
[class]{}-[func]{postOrder}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="binary_tree_dfs.zig"
|
||||
[class]{}-[func]{preOrder}
|
||||
|
||||
[class]{}-[func]{inOrder}
|
||||
|
||||
[class]{}-[func]{postOrder}
|
||||
```
|
||||
|
||||
=== "Dart"
|
||||
|
||||
```dart title="binary_tree_dfs.dart"
|
||||
@@ -225,6 +205,26 @@
|
||||
[class]{}-[func]{post_order}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="binary_tree_dfs.c"
|
||||
[class]{}-[func]{preOrder}
|
||||
|
||||
[class]{}-[func]{inOrder}
|
||||
|
||||
[class]{}-[func]{postOrder}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="binary_tree_dfs.zig"
|
||||
[class]{}-[func]{preOrder}
|
||||
|
||||
[class]{}-[func]{inOrder}
|
||||
|
||||
[class]{}-[func]{postOrder}
|
||||
```
|
||||
|
||||
!!! note
|
||||
|
||||
深度优先搜索也可以基于迭代实现,有兴趣的同学可以自行研究。
|
||||
|
||||
Reference in New Issue
Block a user