Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

练习题14.1-6官方的答案是正确的 #307

Open
leewwe opened this issue Sep 20, 2019 · 0 comments
Open

练习题14.1-6官方的答案是正确的 #307

leewwe opened this issue Sep 20, 2019 · 0 comments

Comments

@leewwe
Copy link

leewwe commented Sep 20, 2019

正确的官方答案

When inserting node z, we search down the tree for the proper place for z. For each node x on this path, add 1 to x.rank if z is inserted within x’s left subtree, and leave x.rank unchanged if z is inserted within x’s right subtree. Similarly when deleting, subtract 1 from x.rank whenever the spliced-out node had been in x’s left subtree.
We also need to handle the rotations that occur during the fixup procedures for insertion and deletion. Consider a left rotation on node x, where the pre-rotation right child of x is y (so that x becomes y’s left child after the left rotation).We leave x.rank unchanged, and letting r = y.rank before the rotation, we set y.rank = r + x.rank. Right rotations are handled in an analogous manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant