java 倾斜堆合并
不一定是java,但我试图理解倾斜堆的合并过程。我不明白为什么步骤中下面的粗体部分是这样的。
- 比较两个堆的根;设 p 为 具有较小根的堆,以及 q 是另一个堆。
- 令 r 为结果的名称 新堆。
- 设 r 的根为 p 的根 (较小的根),并且让 r 是正确的 子树是 p 的左子树。
- 现在,计算 r 的左子树: 递归合并p的右子树 可以沿着
对称轴修改算法(例如我做树的镜像反射)并让r的左子树成为p的右子树并递归地向下合并r的右侧吗?这只是一个惯例还是按照上面列出的方式进行更有效?
Doesnt' have to be java, but I'm trying to understand the merging process for a skew heap. I don't get why the part in bold below in the steps is the way it is.
- Compare roots of two heaps; let p be
the heap with the smaller root, and q
be the other heap. - Let r be the name of the resulting
new heap. - Let the root of r be the root of p
(the smaller root), and let r's right
subtree be p's left subtree. - Now, compute r's left subtree by
recursively merging p's right subtree
with q.
Can the algorithm be modified along an axis of symmetry (e.g I do the mirror reflection of the tree) and let r's left subtree be p's right subtree and recursively merge down the right side of r? Is it just a convention or is it more efficient to do it the way listed above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
左/右的选择完全是任意的,但一旦选择了就必须坚持下去。毕竟,您可以直接获取堆,绘制它的图片,然后镜像它,它仍然是一个有效的堆。其根本原因是,您可以采用任何程序,并左右交换所有出现的变量,结果程序仍然有效,而且做完全相同的事情。
The choice of left/right is completely arbitrary, but once you make it you have to stick with it. After all, you could just take your heap, draw a picture of it, then mirror it and it would still be a valid heap. The underlying reason for this is that you can take any program, and swap all occurrences of the variables left and right, and the resulting program will still be valid, and moreover do exactly the same thing.