Set** chỉ chứa giá trị **duy nhất (unique)**. Dùng Set thay Array khi:
- Biết trước muốn **tránh duplicate**.
- Cần thao tác **union, intersection, difference** — Set có
delete()O(1) vs Array O(n). - Cần **check membership (has)** nhanh — Set O(1) vs Array O(n).
Array** phù hợp khi:
- Cần **thứ tự (ordered)** và **index-based access**.
- Cho phép duplicate.
- Cần binary search, sort.
Kịch bản dùng Set
- Authorization/auth: check membership user trong group.
- Deduplication data stream.
- Toán tập hợp: union, intersect, difference.
Lưu ý: Set **không thay thế Array** — bổ sung cho trường hợp search-heavy, unique-only.