如何实现一套? [英] How to implement a set?

查看:123
本文介绍了如何实现一套?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一组C.
它是确定使用链表,创造了SET的时候,还是应该使用其他方法?

I want to implement a Set in C. Is it OK to use a linked list, when creating the SET, or should I use another approach ?

你通常如何实现自己的一套(如果需要)。

How do you usually implement your own set (if needed).

请注意:
如果我使用链表的方式,我可能有以下的复杂性对我的设置操作:

NOTE: If I use the Linked List approach, I will probably have the following complexities for Set my operations:


  • 初始化:O(1);

  • 破坏:O(N);

  • 插入:O(N);

  • 删除:O(N);

  • 联盟:O(N * M);

  • 十字路口:O(N * M);

  • 的区别:O(N * M);

  • ismember:O(N);

  • issubset:O(N * M);

  • setisequal:O(N * M);

O(N * M)似乎可能会有点变大特别是对庞大的数据...有没有执行我的设置方式更有效?

O(n*m) seems may be a little to big especially for huge data... Is there a way to implement my Set more efficient ?

推荐答案

我已经使用了红黑树在过去建立集。

I have used Red-Black trees in the past to build sets.

下面是来自维基百科的文章时的复杂性。

Here are the time complexities from the Wikipedia article.

空间为O(n)

搜索O(log n)的

插入O(log n)的

删除O(log n)的

Space O(n)
Search O(log n)
Insert O(log n)
Delete O(log n)

这篇关于如何实现一套?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆