diff --git a/en/docs/chapter_searching/index.md b/en/docs/chapter_searching/index.md index 709442ea3..e519df592 100644 --- a/en/docs/chapter_searching/index.md +++ b/en/docs/chapter_searching/index.md @@ -9,9 +9,9 @@ icon: material/text-search !!! abstract - Searching is an unknown adventure, where we may need to traverse every corner of a mysterious space, or perhaps quickly pinpoint our target. + Searching is an adventure into the unknown; where we may need to traverse every corner of a mysterious space, or perhaps we’ll quickly locate our target. - In this journey of discovery, each exploration may yield an unexpected answer. + On this journey of discovery, each exploration may end up with an unexpected answer. ## Chapter contents diff --git a/en/docs/chapter_searching/summary.md b/en/docs/chapter_searching/summary.md index 6750f6399..a8dfd4366 100644 --- a/en/docs/chapter_searching/summary.md +++ b/en/docs/chapter_searching/summary.md @@ -5,8 +5,8 @@ comments: true # 10.6 Summary - Binary search depends on the order of data and performs the search by iteratively halving the search interval. It requires the input data to be sorted and is only applicable to arrays or array-based data structures. -- Brute force search locates data by traversing the data structure. Linear search is suitable for arrays and linked lists, while breadth-first search and depth-first search are suitable for graphs and trees. These algorithms are highly versatile, requiring no preprocessing of data, but have a higher time complexity of $O(n)$. -- Hash search, tree search, and binary search are efficient searching methods, capable of quickly locating target elements in specific data structures. These algorithms are highly efficient, with time complexities reaching $O(\log n)$ or even $O(1)$, but they usually require additional data structures. -- In practice, we need to analyze factors such as data volume, search performance requirements, data query and update frequencies, etc., to choose the appropriate search method. -- Linear search is suitable for small or frequently updated data; binary search is suitable for large, sorted data; hash search is suitable for scenarios requiring high query efficiency without the need for range queries; tree search is appropriate for large dynamic data that needs to maintain order and support range queries. -- Replacing linear search with hash search is a common strategy to optimize runtime, reducing the time complexity from $O(n)$ to $O(1)$. +- Brute force search may be required to locate an entry in an unordered dataset. Different search algorithms can be applied based on the data structure: Linear search is suitable for arrays and linked lists, while breadth-first search (BFS) and depth-first search (DFS) are suitable for graphs and trees. These algorithms are highly versatile, requiring no preprocessing of data, but they have a higher time complexity of $O(n)$. +- Hash search, tree search, and binary search are efficient search methods that can quickly locate target elements within specific data structures. These algorithms are highly efficient, with time complexities reaching $O(\log n)$ or even $O(1)$, but they usually require extra space to accommodate additional data structures. +- In practice, we need to analyze factors such as data volume, search performance requirements, data query and update frequencies, etc., to choose an appropriate search method. +- Linear search is ideal for small or frequently updated (volatile) data. Binary search works well for large and sorted data. Hash search is suitable for data that requires high query efficiency and does not need range queries. Tree search is best suited for large dynamic data that require maintaining order and need to support range queries. +- Replacing linear search with hash search is a common strategy to optimize runtime performance, reducing the time complexity from $O(n)$ to $O(1)$. diff --git a/en/docs/chapter_tree/binary_tree.md b/en/docs/chapter_tree/binary_tree.md index 989814dbd..cbb2745ae 100644 --- a/en/docs/chapter_tree/binary_tree.md +++ b/en/docs/chapter_tree/binary_tree.md @@ -4,7 +4,7 @@ comments: true # 7.1 Binary tree -A binary tree is a non-linear data structure that represents the hierarchical relationship between ancestors and descendants, embodying the divide-and-conquer logic of "splitting into two". Similar to a linked list, the basic unit of a binary tree is a node, each containing a value, a reference to the left child node, and a reference to the right child node. +A binary tree is a non-linear data structure that represents the hierarchical relationship between ancestors and descendants and embodies the divide-and-conquer logic of "splitting into two". Similar to a linked list, the basic unit of a binary tree is a node, and each node contains a value, a reference to its left child node, and a reference to its right child node. === "Python" @@ -202,9 +202,9 @@ A binary tree is a non-linear data structure that represents the hierarch ``` -Each node has two references (pointers), pointing to the left-child node and right-child node, respectively. This node is called the parent node of these two child nodes. When given a node of a binary tree, we call the tree formed by this node's left child and all nodes under it the left subtree of this node. Similarly, the right subtree can be defined. +Each node has two references (pointers), pointing respectively to the left-child node and right-child node. This node is called the parent node of these two child nodes. When given a node of a binary tree, we call the tree formed by this node's left child and all nodes below it the left subtree of this node. Similarly, the right subtree can be defined. -**In a binary tree, except for leaf nodes, all other nodes contain child nodes and non-empty subtrees.** As shown in Figure 7-1, if "Node 2" is considered as the parent node, then its left and right child nodes are "Node 4" and "Node 5," respectively. The left subtree is "the tree formed by Node 4 and all nodes under it," and the right subtree is "the tree formed by Node 5 and all nodes under it." +**In a binary tree, except leaf nodes, all other nodes contain child nodes and non-empty subtrees.** As shown in Figure 7-1, if "Node 2" is regarded as a parent node, its left and right child nodes are "Node 4" and "Node 5" respectively. The left subtree is formed by "Node 4" and all nodes beneath it, while the right subtree is formed by "Node 5" and all nodes beneath it. { class="animation-figure" } @@ -214,13 +214,13 @@ Each node has two references (pointers), pointing to the left-child node The commonly used terminology of binary trees is shown in Figure 7-2. -- Root node: The node at the top level of the binary tree, which has no parent node. -- Leaf node: A node with no children, both of its pointers point to `None`. -- Edge: The line segment connecting two nodes, i.e., node reference (pointer). -- The level of a node: Incrementing from top to bottom, with the root node's level being 1. -- The degree of a node: The number of children a node has. In a binary tree, the degree can be 0, 1, or 2. -- The height of a binary tree: The number of edges passed from the root node to the farthest leaf node. -- The depth of a node: The number of edges passed from the root node to the node. +- Root node: The node at the top level of a binary tree, which does not have a parent node. +- Leaf node: A node that does not have any child nodes, with both of its pointers pointing to `None`. +- Edge: A line segment that connects two nodes, representing a reference (pointer) between the nodes. +- The level of a node: It increases from top to bottom, with the root node being at level 1. +- The degree of a node: The number of child nodes that a node has. In a binary tree, the degree can be 0, 1, or 2. +- The height of a binary tree: The number of edges from the root node to the farthest leaf node. +- The depth of a node: The number of edges from the root node to the node. - The height of a node: The number of edges from the farthest leaf node to the node. { class="animation-figure" } @@ -229,13 +229,13 @@ The commonly used terminology of binary trees is shown in Figure 7-2. !!! tip - Please note that we typically define "height" and "depth" as "the number of edges traversed", but some problems or textbooks may define them as "the number of nodes traversed". In such cases, both height and depth need to be incremented by 1. + Please note that we usually define "height" and "depth" as "the number of edges traversed", but some questions or textbooks may define them as "the number of nodes traversed". In this case, both height and depth need to be incremented by 1. ## 7.1.2 Basic operations of binary trees ### 1. Initializing a binary tree -Similar to a linked list, begin by initialize nodes, then construct references (pointers). +Similar to a linked list, the initialization of a binary tree involves first creating the nodes and then establishing the references (pointers) between them. === "Python" @@ -619,13 +619,13 @@ Similar to a linked list, inserting and removing nodes in a binary tree can be a !!! tip - It's important to note that inserting nodes may change the original logical structure of the binary tree, while removing nodes typically involves removing the node and all its subtrees. Therefore, in a binary tree, insertion and removal are usually performed through a coordinated set of operations to achieve meaningful outcomes. + It should be noted that inserting nodes may change the original logical structure of the binary tree, while removing nodes typically involves removing the node and all its subtrees. Therefore, in a binary tree, insertion and removal are usually performed through a set of operations to achieve meaningful outcomes. ## 7.1.3 Common types of binary trees ### 1. Perfect binary tree -As shown in Figure 7-4, in a perfect binary tree, all levels of nodes are fully filled. In a perfect binary tree, the degree of leaf nodes is $0$, while the degree of all other nodes is $2$; if the tree's height is $h$, then the total number of nodes is $2^{h+1} - 1$, showing a standard exponential relationship, reflecting the common phenomenon of cell division in nature. +As shown in Figure 7-4, in a perfect binary tree, all levels are completely filled with nodes. In a perfect binary tree, leaf nodes have a degree of $0$, while all other nodes have a degree of $2$. The total number of nodes can be calculated as $2^{h+1} - 1$, where $h$ is the height of the tree. This exhibits a standard exponential relationship, reflecting the common phenomenon of cell division in nature. !!! tip @@ -637,7 +637,7 @@ As shown in Figure 7-4, in a perfect binary tree, all levels of nodes are ### 2. Complete binary tree -As shown in Figure 7-5, a complete binary tree has only the bottom level nodes not fully filled, and the bottom level nodes are filled as far left as possible. +As shown in Figure 7-5, a complete binary tree is a binary tree where only the nodes in the bottom level are not completely filled, and the nodes in the bottom level are filled from left to right as much as possible. Please note that a perfect binary tree is also a complete binary tree. { class="animation-figure" } @@ -645,7 +645,7 @@ As shown in Figure 7-5, a complete binary tree has only the bottom level ### 3. Full binary tree -As shown in Figure 7-6, a full binary tree has all nodes except leaf nodes having two children. +As shown in Figure 7-6, a full binary tree, except for the leaf nodes, has two child nodes for all other nodes. { class="animation-figure" } @@ -653,7 +653,7 @@ As shown in Figure 7-6, a full binary tree has all nodes except leaf node ### 4. Balanced binary tree -As shown in Figure 7-7, in a balanced binary tree, the absolute difference in height between the left and right subtrees of any node does not exceed 1. +As shown in Figure 7-7, in a balanced binary tree, the absolute difference between the height of the left and right subtrees of any node does not exceed 1. { class="animation-figure" } @@ -663,14 +663,14 @@ As shown in Figure 7-7, in a balanced binary tree, the absolute differenc Figure 7-8 shows the ideal and degenerate structures of binary trees. A binary tree becomes a "perfect binary tree" when every level is filled; while it degenerates into a "linked list" when all nodes are biased toward one side. -- The perfect binary tree is the ideal situation, fully leveraging the "divide and conquer" advantage of binary trees. -- A linked list is another extreme, where operations become linear, degrading the time complexity to $O(n)$. +- A perfect binary tree is an ideal scenario where the "divide and conquer" advantage of a binary tree can be fully utilized. +- On the other hand, a linked list represents another extreme where all operations become linear, resulting in a time complexity of $O(n)$. { class="animation-figure" }
Figure 7-8 The Best and Worst Structures of Binary Trees
-As shown in Table 7-1, in the best and worst structures, the number of leaf nodes, total number of nodes, and height of the binary tree reach their maximum or minimum values. +As shown in Table 7-1, in the best and worst structures, the binary tree achieves either maximum or minimum values for leaf node count, total number of nodes, and height.Table 7-1 The Best and Worst Structures of Binary Trees
diff --git a/en/docs/index.html b/en/docs/index.html index 01a95b5a5..1ccff9cc9 100644 --- a/en/docs/index.html +++ b/en/docs/index.html @@ -414,7 +414,7 @@This book has been optimized by the efforts of over 180 contributors. We sincerely thank them for their invaluable time and contributions!
+This book has been refined by the efforts of over 180 contributors. We sincerely thank them for their invaluable time and contributions!