Fundamentals of data structures: Vectors
A vector, in computing, is generally a one-dimensional array, typically storing numbers. Vectors typically have fixed sizes, unlike lists and queues.
The vector data structure can be used to represent the mathematical vector used in linear algebra. See related pages for mathematical vector operations. Vectors are often used in computing in computer graphics and simulating physical systems.
Vectors are also used in natural language processing in computing, as a compact way to represent documents as counts of occurrences of words. For instance, the two sentences "It was the best of times, it was the worst of times" and "It was the age of wisdom, it was the age of foolishness" could be represented as two vectors:
"It was the best…" | "It was the age…" | |
---|---|---|
age | 0 | 2 |
best | 1 | 0 |
foolishness | 0 | 1 |
it | 2 | 2 |
of | 2 | 2 |
the | 2 | 2 |
times | 2 | 0 |
was | 2 | 2 |
wisdom | 0 | 1 |
worst | 1 | 0 |
Key Formulas you should know
[edit | edit source]There are several formulas that you may be asked to use in the exam. Below they are listed along with a brief description.
Adding and subtracting values:
This is done fairly simply by adding or subtracting each element to the corresponding one in the other vector. (x, y) + (x, y) = (2x, 2y)
Convex combination of two vectors
This is expressed in the form αυ+β where α+Β=1.
For example, with the vectors (5, 3) and (4, 2) the convex of the two would be 0.7*(5, 3) +0.3*(4, 2) = (4.7, 2.7)
Dot Product of two vectors
This is simply when each component of each vector is multiplied by the corresponding component.
For example, u•v = x1*x2 + y1*y2
Finding the angle between two vectors
cosθ = (u•v) / (||u|| •||v||)