tags:

views:

2959

answers:

11

The question's pretty self-explanatory really. I know vaguely about vectors in maths, but I don't really see the link to C++ vectors. Thanks!

+1  A: 

A vector is simply a sequence of values, all of the same type. This is pretty much in line with the use in mathematics. I guess the mathematical idea that vectors should support some common operations (such as adding, and scaling by a scalar) are not carried over, the important aspect is mainly the structure.

unwind
A: 

I'd guess it comes from the term row vector. Also, computer scientists love thinking up new names for things...

anon
+3  A: 

Also if you make it store integers or floating points it does make an excellent type for storing N dimensional vectors. After all all a vector is, is a list of numbers kept in a specific order.

James Matta
+40  A: 

Mathematical definition of a vector is a member of the set Sn, which is an ordered sequence of values in a specific set (S). This is what a C++ vector stores.

Mehrdad Afshari
I see. I always imagined vectors as 2- or 3-dimensional, so I didn't see the connection with multi-dimensional vectors...
Skilldrick
Vectors are only typically considered 2-3 dimensional because of their use in physics. But more generally in mathematics, they just mean a set of numbers that has an order (mathematical sets are orderless, they're like a bag filled with stuff). A vector can have any number of elements.
Joseph Garvin
@Skilldrick you're confusing vector in geometry or physics (Euclidean vector) with vector in linear algebra (coordinate vector).
vartec
vartec, can't a Euclidean vector be represented as a coordinate vector and vice versa? They're just different representations of the same thing (a tuple) in Euclidian space versus the more general vector space.
Calvin
@Joseph Garvin: Vectors don't even need to have components that are numbers. For example, certain sets of functions can be used to form vector spaces where the components are functions.
Jason
+10  A: 

The name comes from the linear algebra, where vector is matrix with only one column or only one row.

vartec
+2  A: 

No idea about the real reason, but C++ calling it a vector instead of an array, reduces confusion between the C and C++ structures, although they fulfill the same roles.

Robert Gould
+9  A: 

An excerpt from The C++ Programming Language by Bjarne Stroustrup:

"One could argue that valarray should have been called vector because it is a traditional mathematical vector and that vector should have been called array. However, this is not the way the terminology evolved."

aib
Pfftt.. what does that guy know. I've never even heard of this "Bjarne Stroustrup" person.
Calvin
+7  A: 

Just to say why it probably isn't called array: Because std::vector has a dynamic size. An array conceptually is fixed in length. Next C++ Standard by the way has a std::array template, which is fixed in size and should be preferred over a plain array:

std::array<int, 4> f = { 1, 2, 3, 4 };
Johannes Schaub - litb
Has that new C++ standard been released yet?
Johannes Jensen
+28  A: 

It's called a vector because Alex Stepanov, the designer of the Standard Template Library, was looking for a name to distinguish it from built-in arrays. He admits now that he made a mistake, because mathematics already uses the term 'vector' for a fixed-length sequence of numbers. Now C++0X will compound this mistake by introducing a class 'array' that will behave similar to a mathematical vector.

Alex's lesson: be very careful every time you name something.

Mark Ruzon
Very interesting, thanks!
Skilldrick
But array will also don't use heap allocation which makes moving it less efficiently. We also have std::valarray, btw.
sellibitze
A: 

So the real question is why is a physics vector (magnitue+direction) called a vector?

Martin Beckett
A vector is literally a "carrier". The same word is used for (e.g.) insects that transmit disease, and comes from the same Latin root as "vehicle". So it's something that takes you from one place to another. Incidentally, the word "matrix" is also from Latin, meaning "womb".
Artelius
@Artelius - thanks after 20years a physicist I never knew that!
Martin Beckett
A: 

Wonders that parametrisation on types does to names..

here a column gets blasted.. (view source for some server-side ASP.NET HTML encoding skills)

or was it a row?

Then again, thinking of it in MIMD or even SSE vector machine context, the name still sounds damn good.

rama-jka toti