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
fix(ds/leftist-tree.md): 修改左偏树任意节点删除操作 #5547
base: master
Are you sure you want to change the base?
Conversation
感谢你对 OI Wiki 的关注!记得检查是否遵守了格式规范,听说和项目风格统一的 Pull Request 会更容易被 Merge~ |
|
@llleixx PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大体思路是对的。
但 erase 函数有个 corner case 没考虑到,如果删除节点是根节点,那没有正确维护根节点的父亲(0)。
然后 erase 函数不需要递归,所以不用特判 !x(96 行)。
erase 函数中的 pushup(y) 应为 pushup(t[y].fa)。
解决:
把 t[y].fa = t[x].fa 从两个 if 和 else if 块中拿出来(100 行和 104 行);删去 96 行;修改 pushup(y) 为 pushup(t[y].fa)。
还有原文档这块的复杂度证明也写得不是很清楚,可以考虑顺带细化一下。
复杂度分为两部分:一部分 merge 递归,前面已证
;另一部分 pushup 递归(也就是原文档的证明),但那块证明的前提是代替删除节点位置的新节点的 dist 最多减少
(尽管比较显然)。
@JiZiQian WDYT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint finished, ready for review :)
源代码中实现方法的复杂度有误