How to implement a set ?
Posted
by nomemory
on Stack Overflow
See other posts from Stack Overflow
or by nomemory
Published on 2010-03-29T12:08:44Z
Indexed on
2010/03/29
12:13 UTC
Read the original article
Hit count: 172
c
|data-structures
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 my operations:
- init : O(1);
- destroy: O(n);
- insert: O(n);
- remove: O(n);
- union: O(n*m);
- intersection: O(n*m);
- difference: O(n*m);
- ismember: O(n);
- issubset: O(n*m);
- setisequal: 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 ?
© Stack Overflow or respective owner