Set (abstract data type)
Abstract data type that can store unique values, without any particular order. It is a computer implementation of the mathematical concept of a finite set. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests a value for membership in a set.
— Wikipedia
So main set feature is that it can store only unique values.
Basic uses of set is membership testing and eliminating duplicate entries. Set objects also support (at least in Python) mathematical operations like union, intersection, difference, and symmetric difference.
Set seems so similar (especially array-based set) to the array but operations performed on the set are different, mainly on ==insert operation==, in worst case 2N+1. It has different efficiency, because we have non-duplicating constraint. But it perfectly replaces array, when you need unique data.
Sets can be suitable for any lists of unique data (phone numbers, email addresses, etc.).
Reading (access) from a set take one step, like array.
Searching a set takes up to == steps, where is a number of items in the set==, like array.
Deletion from set takes == steps, delete and move data to the left to close gap==, like array.
Insertion is different. You need to ensure that you don’t have duplicate data and this means every insertion into a set first requires a search operation.
In best case insertion into set takes:
Insert into end of set. steps. steps → search, 1 step to insert into
end.
In worst case insertion into set takes (steps):
Insert into beginning of set is worst case scenario. In contrast to insertion
into the begging of a regular array (), insertion can take steps.
Formula: search steps + shift steps + insert 1 step. In other words we
add search operation to insert value into set.