集合的位向量实现

发布于 2024-12-07 12:38:03 字数 476 浏览 1 评论 0原文

在阅读 aho 的数据结构书中有关集合基本操作的章节时,我在集合的位向量实现主题中遇到了以下行...

if the universal set is sufficiently small so that a bit vector fits in one computer word,
then union, intersection and difference can be performed by single logical operations in
the language of the underlying machine..  

集合的位向量实现意味着集合由一个数组表示,该数组的下标表示集合的元素,如果它是数组的成员,则下标的内容为 1,如果不是数组的成员,则为 0...所以成员、插入和删除操作可以在恒定的时间内执行... .但是谁能告诉我如何执行交集、并集和差集摘录中所述的单个逻辑操作...请为这三个操作中的任何一个给出一个示例(或代码)...

while reading the chapter on basic operations on sets from the book of data structures by aho i came across the following line in the topic bit vector implementation of sets...

if the universal set is sufficiently small so that a bit vector fits in one computer word,
then union, intersection and difference can be performed by single logical operations in
the language of the underlying machine..  

a bit vector implementation of sets implies that a set is denoted by an array whose subscripts denote the elements of the set and the content of a subscript is one if it is the member of an array and zero if not....so member, insert and delete operations can be performed in a constant amount of time....but can anyone show me how intersection, union and difference can be performed by single logic operations as stated by the excerpt...plz give an example(or code) for any one of the three operations....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡淡绿茶香 2024-12-14 12:38:03

假设您有一台具有 32 位字的计算机,并且您想要在具有 32 个元素的域上表示集合。例如 {0...31} 的子集。

集合用单个整数表示,其中当且仅当 x 在集合中时,位# x 才为 1。因此,按照惯例,集合 {0, 1, 17, 30} 将是

01000000000000100000000000000011

从 31 到 0,从左到右对位进行编号。

使用以下表示形式:

  • 交集是二进制 AND (x & y)
  • 并集是二进制 OR (x | y)
  • 集合差是二进制 AND NOT (x & ~y)
  • 对称集差是二进制 XOR (x ^ y)

Lets suppose you have a computer with a 32-bit word and you want to represent sets over a domain with 32 elements. For example subsets of {0...31}.

Sets are represented with a single integer in which bit# x is 1 if and only if x is in the set. So the set {0, 1, 17, 30} would be

01000000000000100000000000000011

We number bits from 31 to 0, left to right, by convention.

With this representation:

  • Intersection is a binary AND (x & y)
  • Union is a binary OR (x | y)
  • Set difference is a binary AND NOT (x & ~y)
  • Symmetric set difference is a binary XOR (x ^ y)
无法言说的痛 2024-12-14 12:38:03

给定集合 s1s2

  • 交集为 s1 和 s2。 s2
  • 联合是 s1 | s2 的
  • 区别是 s1 和 s2 ~s2

Given sets s1 and s2,

  • Intersection is s1 & s2
  • Union is s1 | s2
  • Difference is s1 & ~s2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文