[英]Deletion from B tree
I have question in my homework its about b-tree deletion with minimum branching factor t=2. 我在作业中有一个疑问,它涉及以最小分支因子t = 2删除b树。
[P]
/ \
/ \
/ \
/ \
/ \
[G][L] [W]
/ | \ / \
/ | \ / \
/ | \ / \
BD J N R Y
/ | \ / \ / \ / \ / \
A C F I K M O Q ST X Z
Now after deleting Y from the above tree i get the final tree.. 现在从上述树中删除Y后,我得到了最后一棵树。
[P]
/ \
/ \
/ \
/ \
/ \
[G][L] [W]
/ | \ / \
/ | \ / \
/ | \ / \
BD J N R X
/ | \ / \ / \ / \ / \
A C F I K M O Q S T Z
Will this be the final tree after Deleting Y... i am not sure thats why posting here to be corrected..thankss 这将是删除Y之后的最后一棵树吗...我不确定这就是为什么要在此处进行更正..谢谢
I don't think it's correct, T cannot be in the right sub-tree of W since T comes before W. 我认为这是不对的,因为T在W之前,所以T不能在W的正确子树中。
[P]
/ \
/ \
/ \
/ \
/ \
[G][L] [T]
/ | \ / \
/ | \ / \
/ | \ / \
BD J N R X
/ | \ / \ / \ / \ / \
A C F I K M O Q S W Z
Here are the steps: 步骤如下:
Remove Y: 移除Y:
[P]
/ \
/ \
/ \
/ \
/ \
[G][L] [W]
/ | \ / \
/ | \ / \
/ | \ / \
BD J N R null
/ | \ / \ / \ / \ / \
A C F I K M O Q ST X Z
Replace with smallest from right sub-tree (Z), rebalance at Z's old location 用右侧子树(Z)中最小的替换,在Z的旧位置重新平衡
[P]
/ \
/ \
/ \
/ \
/ \
[G][L] [W]
/ | \ / \
/ | \ / \
/ | \ / \
BD J N R Z
/ | \ / \ / \ / \ /
A C F I K M O Q ST X
Cannot borrow from sibling (X), merge children at Z: 无法从同级(X)借用,在Z处合并子代:
[P]
/ \
/ \
/ \
/ \
/ \
[G][L] [W]
/ | \ / \
/ | \ / \
/ | \ / \
BD J N R [X,Z]
/ | \ / \ / \ / \
A C F I K M O Q ST
Cannot borrow from sibling (R), merge children at W: 无法从同级(R)借用,在W处合并子代:
[P]
/ \
/ \
/ \
/ \
/ \
[G][L] [Q,R,S,T,W,X,Z]
/ | \
/ | \
/ | \
BD J N
/ | \ / \ / \
A C F I K M O
Merged node (previously W) is now too large, split evenly: 合并的节点(以前为W)现在太大,平均分配:
[P]
/ \
/ \
/ \
/ \
/ \
[G][L] [T]
/ | \ / \
/ | \ [Q,R,S] [W,X,Z]
/ | \
BD J N
/ | \ / \ / \
A C F I K M O
Left node of T is now too large, split evenly: T的左节点现在太大了,请平均分配:
[P]
/ \
/ \
/ \
/ \
/ \
[G][L] [T]
/ | \ / \
/ | \ / [W,X,Z]
/ | \ /
BD J N R
/ | \ / \ / \ / \
A C F I K M O Q S
Right node of T is also too large, split evenly: T的右节点也太大,平均分配:
[P]
/ \
/ \
/ \
/ \
/ \
[G][L] [T]
/ | \ / \
/ | \ / \
/ | \ / \
BD J N R X
/ | \ / \ / \ / \ / \
A C F I K M O Q S W Z
it is so good question. 这是一个很好的问题。 L goes to the root, P goes to it's right child and sit near WN and it's children becomes left child of P for delete Y, W must go middle down of R and YY goes down between X and Z now you can delete Y ... L移到根,P移到它的右子并坐在WN附近,它的子成为P的左子,以删除Y,W必须移到R的中间,而YY在X和Z之间向下移,现在您可以删除Y .. 。
[ L ]
/ \
!!!!!! !!!!!! / \\ / \\ / \\ / \\ / / / \\ / \\ / \\
[G] [P] / \\ / \\ / \\ / \\ / \\ / \\ [BD] [J] NRW [G] [P] / \\ / \\ / \\ / \\ / \\ / \\ [BD] [J] NRW
/ | / | \\ / \\ / \\ / | \\ / \\ / \\ / | | \\ \\
ACFIKMOQ ST XZ --->Y ACFIKMOQ ST XZ ---> Y
it is so good question. 这是一个很好的问题。 L goes to the root, P goes to it's right child and sit near WN and it's children becomes left child of P for delete Y, W must go middle down of R and YY goes down between X and Z now you can delete Y ... L移到根,P移到它的右子并坐在WN附近,它的子成为P的左子,以删除Y,W必须移到R的中间,而YY在X和Z之间向下移,现在您可以删除Y .. 。
[ L ]
/ \
/ \
/ \
/ \
/ \
[G] [P]
/ \ / \
/ \ / \
/ \ / \
[B D] [J] N R W
/ | \ / \ / \ / | \
A C F I K M O Q ST X Z --->Y
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.