🔒
Pro Content
Subscribe to access all 69 OCR H446 A Level lessons.
£7.99/month
or £59/year
Subscribe now →
🔒 Pro · Component 1 · 1.4.2 Data Structures
1.4.2f Vectors
OCR H446 · A Level Computer Science · ~12 min read
Notes
Video
Slides
Worksheet
Quiz

Vectors in Computer Science

In OCR H446, a vector is a mathematical object representing a quantity with both magnitude and direction, represented as an ordered list of numbers (components). Vectors are used extensively in computer graphics, physics simulations, machine learning, and data science.

A vector can also refer to a 1D array of numbers in computing. Both definitions are relevant — the mathematical properties directly inform how they are implemented and used.

Vector Notation and Representation

An n-dimensional vector is written as an ordered tuple of n real numbers:

-- 2D vector (x, y components): v = (3, 4) -- 3 units right, 4 units up -- 3D vector (x, y, z components): u = (1, 2, 5) -- n-dimensional vector: v = (v₁, v₂, v₃, ..., vₙ)

Vectors can also be written as column vectors (matrices with one column) or as lists/arrays in code.

Vector Operations

1. Vector Addition

Add corresponding components: (a₁, a₂) + (b₁, b₂) = (a₁+b₁, a₂+b₂)

(3, 4) + (1, -2) = (3+1, 4+(-2)) = (4, 2)

2. Scalar Multiplication

Multiply each component by a scalar k: k × (a₁, a₂) = (k×a₁, k×a₂)

3 × (2, 5) = (6, 15) -1 × (3, 4) = (-3, -4) -- reverses direction

3. Dot Product (Scalar Product)

Produces a scalar: a · b = a₁×b₁ + a₂×b₂ + ... + aₙ×bₙ

-- Example: (3, 4) · (1, 2) = (3×1) + (4×2) = 3 + 8 = 11 -- Geometric interpretation: a · b = |a| × |b| × cos(θ) -- where θ is the angle between vectors -- If a · b = 0, vectors are perpendicular (cos 90° = 0)

4. Vector Magnitude (Length)

The magnitude (or length/norm) of vector v = (a, b) is:

|v| = √(a² + b²) -- 2D |v| = √(a² + b² + c²) -- 3D -- Example: |(3, 4)| = √(9 + 16) = √25 = 5

5. Unit Vector (Normalisation)

A unit vector has magnitude 1. To normalise vector v: divide each component by |v|.

v = (3, 4), |v| = 5 unit_v = (3/5, 4/5) = (0.6, 0.8) -- Check: √(0.6² + 0.8²) = √(0.36+0.64) = √1 = 1 ✓

Convex Combination of Vectors

A convex combination of two vectors u and v is: w = (1−t)u + tv, where 0 ≤ t ≤ 1. As t goes from 0 to 1, w moves linearly from u to v — this is used for interpolation in graphics (e.g. blending colours, smooth animation transitions).

-- Midpoint (t = 0.5): u = (2, 4), v = (8, 0) w = 0.5 × (2,4) + 0.5 × (8,0) = (1,2) + (4,0) = (5, 2)

Vectors in Computing Applications

ApplicationHow Vectors are Used
Computer graphics (2D/3D)Position vectors, velocity, direction of light, surface normals
Physics enginesForce vectors, acceleration, velocity; vector addition for resultant force
Machine learningFeature vectors (each dimension = one feature); word embeddings
Computer visionImage as vector of pixel values; distance between image vectors for similarity
GPS/NavigationPosition and displacement vectors; finding shortest path direction
CryptographyLattice-based cryptography uses high-dimensional vectors

Representing Vectors in Code

Vectors are typically implemented as one-dimensional arrays or lists:

-- Python example: v = [3, 4] u = [1, 2] -- Addition: result = [v[i] + u[i] for i in range(len(v))] -- [4, 6] -- Dot product: dot = sum(v[i] * u[i] for i in range(len(v))) -- 11 -- Magnitude: import math mag = math.sqrt(sum(x**2 for x in v)) -- 5.0

Summary of Operations

OperationFormulaResult type
Addition(a₁+b₁, a₂+b₂, ...)Vector
Scalar multiplication(k×a₁, k×a₂, ...)Vector
Dot producta₁b₁ + a₂b₂ + ... + aₙbₙScalar
Magnitude√(a₁² + a₂² + ... + aₙ²)Scalar
Normalisationv / |v|Vector (unit vector)
Convex combination(1-t)u + tv, 0 ≤ t ≤ 1Vector (on line between u,v)
Exam tip: The dot product of two vectors is a SCALAR (single number), not another vector. The formula is: sum of products of corresponding components. The dot product is zero when vectors are perpendicular (angle = 90°). This property is used in 3D graphics for lighting calculations (how much a surface faces a light source).
Exam tip: A unit vector has magnitude exactly 1. To find the unit vector, divide each component by the original vector's magnitude. The magnitude of a 2D vector (a, b) = √(a² + b²) — Pythagoras' theorem in n dimensions.
⚠ Common Mistakes
  • The dot product gives a scalar, not a vector. Cross product (not in H446) gives a vector. In exams: "dot product of (2,3) and (4,1) = 2×4 + 3×1 = 11" — a number.
  • Forgetting the square root when computing magnitude — |(3,4)| = 5, not 25.
  • Confusing vectors (magnitude + direction) with scalars (magnitude only). Speed is scalar; velocity is vector.
✓ Notes completed!
Video coming soon
Click to advance · Arrow keys also work
Click slide or press arrow keys to navigate

Worksheet — 1.4.2f Vectors

8 questions · 20 marks · instantly marked

Q1Define a vector in computing. State two properties that distinguish a vector from a scalar.[3 marks]
✓ Mark scheme
A vector is a mathematical object representing a quantity with both magnitude (size) and direction, stored as an ordered list of n numeric components [1]. Properties distinguishing it from a scalar: (1) vectors have direction, scalars do not [1]; (2) vectors are ordered tuples of multiple components; scalars are single numbers [1]. Example: speed is scalar, velocity is vector.
Q2Calculate: (a) (5, 2) + (−1, 7) and (b) 4 × (3, −2).[2 marks]
✓ Mark scheme
(a) (5+(−1), 2+7) = (4, 9) [1]. (b) (4×3, 4×(−2)) = (12, −8) [1].
Q3Calculate the dot product of (2, 5) and (4, −1). What type of value does the dot product always produce?[3 marks]
✓ Mark scheme
(2×4) + (5×(−1)) = 8 + (−5) = 3 [2]. The dot product always produces a scalar (a single number, not a vector) [1].
Q4Calculate the magnitude of vector (6, 8). Show your working.[2 marks]
✓ Mark scheme
|v| = √(6² + 8²) = √(36 + 64) = √100 = 10 [2]. Method mark for √(a²+b²) [1], answer mark for 10 [1].
Q5Find the unit vector in the direction of (0, 5). Verify your answer has magnitude 1.[3 marks]
✓ Mark scheme
|v| = √(0² + 5²) = √25 = 5 [1]. Unit vector = (0/5, 5/5) = (0, 1) [1]. Verification: √(0² + 1²) = √1 = 1 ✓ [1].
Q6Calculate the convex combination of u = (4, 0) and v = (0, 8) at t = 0.25. What does this operation represent geometrically?[3 marks]
✓ Mark scheme
w = (1−0.25)(4,0) + 0.25(0,8) = 0.75(4,0) + 0.25(0,8) = (3,0) + (0,2) = (3, 2) [2]. Geometrically: the convex combination finds a point on the straight line between u and v. At t=0.25, the point is 25% of the way from u to v [1]. Used in graphics for interpolation/animation.
Q7Two vectors a = (1, 0) and b = (0, 1) are perpendicular. Verify this using the dot product.[2 marks]
✓ Mark scheme
a · b = (1×0) + (0×1) = 0 + 0 = 0 [1]. When the dot product is 0, the vectors are perpendicular (cos 90° = 0, so a · b = |a||b|cos(90°) = 0) [1].
Q8Give two real-world computing applications where vectors are used, explaining briefly how they are applied in each.[4 marks]
✓ Mark scheme
Any two of [2 marks each]: Computer graphics — 3D position and direction of objects represented as vectors; lighting calculations use dot product to determine how much a surface faces a light source [2]. Machine learning — feature vectors (each dimension = one feature of a data item); similarity between items measured by dot product or distance between vectors [2]. Physics engines — velocity, force, and acceleration represented as vectors; vector addition used to calculate resultant force on an object [2]. GPS/navigation — displacement vectors for calculating direction and distance between coordinates [2].
Topic Quiz
1 of 15
You scored
out of 15
🎯

Mini Test — 1.4.2f Vectors

  • 10 questions · 10 marks · 10 minutes
  • 5 MCQ + 5 short answer
Card 1 of 15
Click to reveal
🎉
Complete!
TermDefinition
← 1.4.2e Hash Tables 1.4.2 Data Structures Next: 1.4.2g Recursion →