Skip to content

Commit 596a42c

Browse files
committed
Fix 2-3 tree documentation error - Fixes #275
Corrects the description of 2-3 tree node structure in section 1.4. Issue: The documentation incorrectly stated that a node can have 1-3 elements. This caused confusion about the tree structure before inserting node 9. Fix: - Corrected: A node can have 1-2 elements (not 1-3) - Added clarification note explaining the correct structure - Clarified that when a node reaches 3 elements, it must be rebalanced immediately - Added specific example about parent node 6 structure before inserting node 9 The fix addresses the concern raised in issue #275 about the tree structure showing parent node 6 should only have one element with node 5 as left subtree. Fixes #275
1 parent 21d96f6 commit 596a42c

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

docs/md/algorithm/data-structures/2022-10-01-tree-2-3.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ lock: need
3939
</div>
4040

4141
- 2-3 树的插入过程与 BST 树类似,会通过树的左右节点大小,找到自己的插入位置。
42-
- 一个节点可以右1-3个元素,但当元素个数为3时,则需要调衡。把三个节点的中间节点晋升上来,其余两个节点为子节点。
42+
- 一个节点可以有1-2个元素(注意:不是1-3个),但当元素个数为3时,则需要调衡。把三个节点的中间节点晋升上来,其余两个节点为子节点。
4343
- 如果进行一次调衡后,上一层父节点达到3个元素,则需要2次调衡,来满足2-3树的规则。
4444

45+
**注意**:2-3树的定义是每个节点可以有1-2个元素,当插入导致节点有3个元素时需要立即调衡。例如在插入节点9之前的树结构中,父节点6应该只有一个元素,其左子树为节点5。这样的结构符合2-3树的定义,也便于后续插入节点9时的调衡操作。
46+
4547
**咋样**,是不看过这个图之后对于2-3树的实现已经有感觉了,想动手写写试试了?
4648
- 源码地址:[https://github.com/fuzhengwei/java-algorithms](https://github.com/fuzhengwei/java-algorithms)
4749
- 本章源码:[https://github.com/fuzhengwei/java-algorithms/tree/main/data-structures/src/main/java/tree](https://github.com/fuzhengwei/java-algorithms/tree/main/data-structures/src/main/java/tree)

0 commit comments

Comments
 (0)