我想实现一组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)