mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-24 17:17:14 +00:00
Revisit the English version (#1885)
* Update giscus scroller. * Refine English docs and landing page * Sync the headings. * Update landing pages. * Update the avatar * Update Acknowledgements * Update landing pages. * Update contributors. * Update * Fix the formula formatting. * Fix the glossary. * Chapter 6. Hashing * Remove Chinese chars. * Fix headings. * Update giscus themes. * fallback to default giscus theme to solve 429 many requests error. * Add borders for callouts. * docs: sync character encoding translations * Update landing page media layout and i18n
This commit is contained in:
@@ -6,7 +6,7 @@ Both graphs and trees require the application of search algorithms to implement
|
||||
|
||||
## Breadth-First Search
|
||||
|
||||
**Breadth-first search is a near-to-far traversal method that, starting from a certain node, always prioritizes visiting the nearest vertices and expands outward layer by layer**. As shown in the figure below, starting from the top-left vertex, first traverse all adjacent vertices of that vertex, then traverse all adjacent vertices of the next vertex, and so on, until all vertices have been visited.
|
||||
**Breadth-first search proceeds from near to far: starting from a given node, it always visits the nearest vertices first and expands outward layer by layer**. As shown in the figure below, starting from the top-left vertex, first traverse all adjacent vertices of that vertex, then traverse all adjacent vertices of the next vertex, and so on, until all vertices have been visited.
|
||||
|
||||

|
||||
|
||||
@@ -22,7 +22,7 @@ To prevent revisiting vertices, we use a hash set `visited` to record which node
|
||||
|
||||
!!! tip
|
||||
|
||||
A hash set can be viewed as a hash table that stores only `key` without storing `value`. It can perform addition, deletion, lookup, and modification operations on `key` in $O(1)$ time complexity. Based on the uniqueness of `key`, hash sets are typically used for data deduplication and similar scenarios.
|
||||
A hash set can be viewed as a hash table that stores only `key` without storing `value`. It supports insertion, deletion, lookup, and update operations on `key` in $O(1)$ time. Based on the uniqueness of `key`, hash sets are typically used for data deduplication and similar scenarios.
|
||||
|
||||
```src
|
||||
[file]{graph_bfs}-[class]{}-[func]{graph_bfs}
|
||||
@@ -90,9 +90,9 @@ This "go as far as possible then return" algorithm paradigm is typically impleme
|
||||
The algorithm flow of depth-first search is shown in the figure below.
|
||||
|
||||
- **Straight dashed lines represent downward recursion**, indicating that a new recursive method has been initiated to visit a new vertex.
|
||||
- **Curved dashed lines represent upward backtracking**, indicating that this recursive method has returned to the position where it was initiated.
|
||||
- **Curved dashed lines represent upward backtracking**, indicating that this recursive call has returned to the point where it was made.
|
||||
|
||||
To deepen understanding, it is recommended to combine the figure below with the code to mentally simulate (or draw out) the entire DFS process, including when each recursive method is initiated and when it returns.
|
||||
To deepen understanding, it is recommended to combine the figure below with the code to mentally simulate (or draw out) the entire DFS process, including when each recursive call begins and when it returns.
|
||||
|
||||
=== "<1>"
|
||||

|
||||
@@ -129,7 +129,7 @@ To deepen understanding, it is recommended to combine the figure below with the
|
||||
|
||||
!!! question "Is the depth-first traversal sequence unique?"
|
||||
|
||||
Similar to breadth-first search, the order of depth-first traversal sequences is also not unique. Given a certain vertex, exploring in any direction first is valid, meaning the order of adjacent vertices can be arbitrarily shuffled, all being depth-first search.
|
||||
Similar to breadth-first search, depth-first traversal sequences are also not unique. Given a vertex, any exploration direction may be chosen first; that is, the order of adjacent vertices can be arbitrarily rearranged and still constitute depth-first search.
|
||||
|
||||
Taking tree traversal as an example, "root $\rightarrow$ left $\rightarrow$ right", "left $\rightarrow$ root $\rightarrow$ right", and "left $\rightarrow$ right $\rightarrow$ root" correspond to pre-order, in-order, and post-order traversals, respectively. They represent three different traversal priorities, yet all three belong to depth-first search.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user