Sets Flashcards
(48 cards)
What is a set in data structures?
A collection of unique elements with no specific order.
What is the key property of a set?
It does not allow duplicate elements.
What are common operations on a set?
Insert, delete, search, union, intersection, difference.
What is the time complexity of insert in a hash set?
O(1) average case.
What is the time complexity of search in a hash set?
O(1) average case.
What is the time complexity of delete in a hash set?
O(1) average case.
What is a hash set?
A set implemented using a hash table.
What is a tree set?
A set implemented using a balanced binary search tree.
What is the time complexity of operations in a tree set?
O(log n).
What is a subset?
A set where all elements are contained in another set.
What is a superset?
A set that contains all elements of another set.
What is the union of two sets?
A set containing all distinct elements from both sets.
What is the intersection of two sets?
A set containing only elements present in both sets.
What is the difference of two sets?
A set containing elements in the first set but not in the second.
How do you check if an element is in a set?
Use the contains or βinβ operator depending on the language.
What is the space complexity of a set?
O(n), where n is the number of elements.
What is the benefit of using a set over a list?
Faster lookups and guaranteed uniqueness.
What is a multiset?
A collection that allows duplicate elements.
What is the main disadvantage of sets?
They do not maintain insertion order (in hash sets).
What is an ordered set?
A set that maintains elements in sorted or insertion order.
What happens if you try to insert a duplicate into a set?
The duplicate is ignored.
What is the mathematical definition of a set?
A well-defined collection of distinct objects.
How do you iterate through a set?
Using a for-loop or an iterator.
What is a power set?
The set of all subsets of a given set.