如何实现一套?

编程入门 行业动态 更新时间:2024-10-27 13:22:40
本文介绍了如何实现一套?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

如何实现一套?

本文发布于:2023-11-30 10:37:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649676.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何实现

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!