#sets
Array Intersection
Array Intersection Array intersection returns the elements that appear in both input arrays. The result can be defined as a set of distinct values or as a multiset that preserves counts. You use it when you need to find overlap between datasets. Problem Given arrays $A$ and $B$, compute: $$ A \cap B $$ Two common variants: distinct intersection: each value appears once multiset intersection: each value appears $\min(count_A, count_B)$...
Array Deduplication
Array Deduplication Array deduplication removes repeated values from an array. The usual method keeps a set of values already seen and writes each new value once. You use it when the array may contain repeated elements and downstream work needs only distinct values. Problem Given an array $A$ of length $n$, produce an array containing each distinct value once. For stable deduplication, preserve the first occurrence order. Algorithm Use a...
Array Union
Array Union Array union combines elements from two arrays and returns all distinct values. It can also be defined as a multiset union that preserves counts. You use it when merging datasets while eliminating duplicates. Problem Given arrays $A$ and $B$, compute: $$ A \cup B $$ Two common variants: distinct union: each value appears once multiset union: each value appears $\max(count_A, count_B)$ times Algorithm For distinct union, use a...