不相交集的链表表示 - 算法简介文本中的遗漏?
成功解决了我的上一个 CLRS 问题, 这是另一个:
算法简介,第二版,第 12 页。 501-502,描述了不相交集合的链表表示,其中每个列表成员维护以下三个字段:
- 将成员
- 指针设置为
下一个
对象 - 指针返回到第一个对象(集合
代表
)。
尽管链表可以仅使用单个“链接”对象类型来实现,但教科书显示了一个辅助“链表”对象,其中包含指向“头”链接和“尾”链接的指针。拥有指向“尾部”的指针有利于Union(x, y)
操作,因此不需要遍历较大集合x
中的所有链接来开始将较小的集合 y
的链接附加到它。
然而,为了获得对尾部链接的引用,似乎每个链接对象都需要维护一个第四字段:对链接列表辅助对象本身的引用。在这种情况下,为什么不完全删除链接列表对象并使用第四个字段直接指向尾部呢?
您认为这是文本中的遗漏吗?
Having had success with my last CLRS question, here's another:
In Introduction to Algorithms, Second Edition, p. 501-502, a linked-list representation of disjoint sets is described, wherein each list member the following three fields are maintained:
- set member
- pointer to
next
object - pointer back to first object (the set
representative
).
Although linked lists could be implemented by using only a single "Link" object type, the textbook shows an auxiliary "Linked List" object that contains a pointer to the "head" link and the "tail" link. Having a pointer to the "tail" facilitates the Union(x, y)
operation, so that one need not traverse all of the links in a larger set x
in order to start appending the links of the smaller set y
to it.
However, to obtain a reference to the tail link, it would seem that each link object needs to maintain a fourth field: a reference to the Linked List auxiliary object itself. In that case, why not drop the Linked List object entirely and use that fourth field to point directly to the tail?
Would you consider this an omission in the text?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚打开文本,教科书的描述对我来说似乎很好。
据我了解,数据结构是这样的:
教科书没有谈到我的书(第二版)中的任何“辅助”链表结构。你能贴出相关段落吗?
建立一个联盟会是这样的:
I just opened the text and the textbook description seems fine to me.
From what I understand the data-structure is something like:
The textbook does not talk of any "auxillary" linked list structure in the book I have (second edition). Can you post the relevant paragraph?
Doing a Union would be something like:
可以从路径压缩中获得见解。所有元素都应该指向列表的头部。如果没有发生,则查找集操作会执行此操作(通过更改 p[x] 并返回它)。你同样谈论尾巴。所以只有实现了这样的功能我们才能使用它。
An insight can be taken from path compression. There all the elements are supposed to point to head of list. If it doesn't happen then the find-set operation does that (by changing p[x] and returning that). You talk similarly of tail. So if such function is implemented only then can we use that.