mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-25 01:36:29 +08:00
Merge 235f4e9fa4
into b6939da46c
This commit is contained in:
commit
b76eb5df0b
1 changed files with 6 additions and 6 deletions
|
@ -1,10 +1,10 @@
|
||||||
# Summary
|
# Summary
|
||||||
|
|
||||||
### Key review
|
### Key Highlights
|
||||||
|
|
||||||
- A binary tree is a non-linear data structure that reflects the "divide and conquer" logic of splitting one into two. Each binary tree node contains a value and two pointers, which point to its left and right child nodes, respectively.
|
- A binary tree is a non-linear data structure that reflects the "divide and conquer" logic of splitting one into two. Each binary tree node contains a value and two pointers, which point to its left and right child nodes, respectively.
|
||||||
- For a node in a binary tree, the tree formed by its left (right) child node and all nodes under it is called the node's left (right) subtree.
|
- For a node in a binary tree, its left (right) child node and the tree formed below it is called the node's left (right) subtree.
|
||||||
- Related terminology of binary trees includes root node, leaf node, level, degree, edge, height, and depth, among others.
|
- Terms related to binary trees include root node, leaf node, level, degree, edge, height, and depth.
|
||||||
- The operations of initializing a binary tree, inserting nodes, and removing nodes are similar to those of linked list operations.
|
- The operations of initializing a binary tree, inserting nodes, and removing nodes are similar to those of linked list operations.
|
||||||
- Common types of binary trees include perfect binary trees, complete binary trees, full binary trees, and balanced binary trees. The perfect binary tree represents the ideal state, while the linked list is the worst state after degradation.
|
- Common types of binary trees include perfect binary trees, complete binary trees, full binary trees, and balanced binary trees. The perfect binary tree represents the ideal state, while the linked list is the worst state after degradation.
|
||||||
- A binary tree can be represented using an array by arranging the node values and empty slots in a level-order traversal sequence and implementing pointers based on the index mapping relationship between parent nodes and child nodes.
|
- A binary tree can be represented using an array by arranging the node values and empty slots in a level-order traversal sequence and implementing pointers based on the index mapping relationship between parent nodes and child nodes.
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
- Pre-order, in-order, and post-order traversals are all depth-first search methods, reflecting the traversal manner of "going to the end first, then backtracking to continue." They are usually implemented using recursion.
|
- Pre-order, in-order, and post-order traversals are all depth-first search methods, reflecting the traversal manner of "going to the end first, then backtracking to continue." They are usually implemented using recursion.
|
||||||
- A binary search tree is an efficient data structure for element searching, with the time complexity of search, insert, and remove operations all being $O(\log n)$. When a binary search tree degrades into a linked list, these time complexities deteriorate to $O(n)$.
|
- A binary search tree is an efficient data structure for element searching, with the time complexity of search, insert, and remove operations all being $O(\log n)$. When a binary search tree degrades into a linked list, these time complexities deteriorate to $O(n)$.
|
||||||
- An AVL tree, also known as a balanced binary search tree, ensures that the tree remains balanced after continuous node insertions and removals through rotation operations.
|
- An AVL tree, also known as a balanced binary search tree, ensures that the tree remains balanced after continuous node insertions and removals through rotation operations.
|
||||||
- Rotation operations in an AVL tree include right rotation, left rotation, right-then-left rotation, and left-then-right rotation. After inserting or removing nodes, an AVL tree performs rotation operations from bottom to top to rebalance the tree.
|
- Rotation operations in an AVL tree include right rotation, left rotation, right-left rotation, and left-right rotation. After inserting or removing nodes, the AVL tree performs rotation operations from bottom to top to rebalance the tree.
|
||||||
|
|
||||||
### Q & A
|
### Q & A
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
Yes, because height and depth are typically defined as "the number of edges passed."
|
Yes, because height and depth are typically defined as "the number of edges passed."
|
||||||
|
|
||||||
**Q**: The insertion and removal in a binary tree are generally completed by a set of operations. What does "a set of operations" refer to here? Can it be understood as the release of resources of the child nodes?
|
**Q**: The insertion and removal in a binary tree are generally accomplished by a set of operations. What does "a set of operations" refer to here? Can it be understood as the release of resources of the child nodes?
|
||||||
|
|
||||||
Taking the binary search tree as an example, the operation of removing a node needs to be handled in three different scenarios, each requiring multiple steps of node operations.
|
Taking the binary search tree as an example, the operation of removing a node needs to be handled in three different scenarios, each requiring multiple steps of node operations.
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ We need to view this problem from a recursive perspective. The `right_rotate(roo
|
||||||
|
|
||||||
**Q**: In C++, functions are divided into `private` and `public` sections. What considerations are there for this? Why are the `height()` function and the `updateHeight()` function placed in `public` and `private`, respectively?
|
**Q**: In C++, functions are divided into `private` and `public` sections. What considerations are there for this? Why are the `height()` function and the `updateHeight()` function placed in `public` and `private`, respectively?
|
||||||
|
|
||||||
It depends on the scope of the method's use. If a method is only used within the class, then it is designed to be `private`. For example, it makes no sense for users to call `updateHeight()` on their own, as it is just a step in the insertion or removal operations. However, `height()` is for accessing node height, similar to `vector.size()`, thus it is set to `public` for use.
|
It depends on the scope of the function's use. If a function is only used within the class, then it is designed to be `private`. For example, it makes no sense for users to call `updateHeight()` on their own, as it is just a step in the insertion or removal operations. However, `height()` is for accessing node height, similar to `vector.size()`, thus it is set to `public` for use.
|
||||||
|
|
||||||
**Q**: How do you build a binary search tree from a set of input data? Is the choice of root node very important?
|
**Q**: How do you build a binary search tree from a set of input data? Is the choice of root node very important?
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue