mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-22 19:36:06 +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:
@@ -8,7 +8,7 @@ The common traversal methods for binary trees include level-order traversal, pre
|
||||
|
||||
As shown in the figure below, <u>level-order traversal</u> traverses the binary tree from top to bottom, layer by layer. Within each level, it visits nodes from left to right.
|
||||
|
||||
Level-order traversal is essentially <u>breadth-first traversal</u>, also known as <u>breadth-first search (BFS)</u>, which embodies a "expanding outward circle by circle" layer-by-layer traversal method.
|
||||
Level-order traversal is essentially <u>breadth-first traversal</u>, also known as <u>breadth-first search (BFS)</u>, which proceeds outward level by level.
|
||||
|
||||

|
||||
|
||||
@@ -27,7 +27,7 @@ Breadth-first traversal is typically implemented with the help of a "queue". The
|
||||
|
||||
## Preorder, Inorder, and Postorder Traversal
|
||||
|
||||
Correspondingly, preorder, inorder, and postorder traversals all belong to <u>depth-first traversal</u>, also known as <u>depth-first search (DFS)</u>, which embodies a "first go to the end, then backtrack and continue" traversal method.
|
||||
Correspondingly, preorder, inorder, and postorder traversals all belong to <u>depth-first traversal</u>, also known as <u>depth-first search (DFS)</u>, which goes as deep as possible before backtracking.
|
||||
|
||||
The figure below shows how depth-first traversal works on a binary tree. **Depth-first traversal is like "walking" around the perimeter of the entire binary tree**, encountering three positions at each node, corresponding to preorder, inorder, and postorder traversal.
|
||||
|
||||
@@ -43,12 +43,12 @@ Depth-first search is usually implemented based on recursion:
|
||||
|
||||
!!! tip
|
||||
|
||||
Depth-first search can also be implemented based on iteration, interested readers can study this on their own.
|
||||
Depth-first search can also be implemented iteratively, and interested readers can explore this on their own.
|
||||
|
||||
The figure below shows the recursive process of preorder traversal of a binary tree, which can be divided into two opposite parts: "recursion" and "return".
|
||||
The figure below shows the recursive process of preorder traversal of a binary tree, which can be divided into two opposite phases: "descending" and "returning".
|
||||
|
||||
1. "Recursion" means opening a new method, where the program accesses the next node in this process.
|
||||
2. "Return" means the function returns, indicating that the current node has been fully visited.
|
||||
1. "Descending" means making a new recursive call, during which the program visits the next node.
|
||||
2. "Returning" means the function call returns, indicating that the current node has been fully processed.
|
||||
|
||||
=== "<1>"
|
||||

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