What are the differences between vectors, sets, and tuples in programming?
A tuple is a heterogeneous collection of objects, which should be treated as a single unit: for example, ("John", "Smith", 30) is a (String, String, Integer) tuple.
A list (in C++: and also vector) is a homogeneous collection of objects -- that is, each object can be treated uniformly. Whether they are actually the same type depends on the language, but the point is that they can be processed the same way.
A set is an unordered unique homogenous collection -- you know what objects it contains, and what type they are, but not in what order, and it only contains one of each object.
Vectors have an ordering
Tuples are ordered and can have repeat elements.
Sets are unordered and repeat elements do not change the set.
For example: {a,b}, {b,a}, and {b,b,a} are all the same set, while (a,b), (b,a) and (b,b,a) are all different tuples.
A vector
is an ordered sequence of items that does allow duplicates.
A set
is a collection of items that is unordered and does not allow duplicates.
A tuple
is an ordered sequence of items of a given length.
Vectors have an ordering, sets do not (and can't have duplicates), and tuples are close to vectors but are usually used more like structs in practice.
the difference is tuples are not meant to be treated as collections, while vectors & sets are.
tuples are meant to represent compound values, like position in a 3d space with (x,y,z) coordinates, it doesn't make sense to see it as a collection, because yes is a list of 3 numbers but the 3 numbers have different meaning and combined form an specific meaning.
Think of tuples as a structs with nameless positional attributes that can have different types. As such is not meant to store lots of values, and this is why all implementations of this things are optimized for a small number of them
an example of tuple is the type used to describe the columns of a single row in a SQL Database, in fact that is who rows are called in Relational Algebra.
A Vector (terrible name by the way) is an ordered collection that is meant to store lots of values it is usually implemented to grow as needed keeping an access of O(1)
a table in a SQL DB without primary key would be a Vector of tuples.
A Set is a collection of unique elements, that can be ordered but it doesn't have to be.
a table in a SQL DB with primary key would be Set of tuples.