Skip to content

Dot Product

Formula

\[ x\cdot y = \sum_{i=1}^n x_i y_i \]

Parameters

  • \(x,y\in\mathbb{R}^n\): vectors

What it means

Measures alignment between vectors; equals \(\|x\|\,\|y\|\cos\theta\).

What it's used for

  • Measuring similarity and angles between vectors.
  • Projection and least squares derivations.

Key properties

  • Bilinear and symmetric
  • Defines length: \(\|x\|_2 = \sqrt{x\cdot x}\)

Common gotchas

  • Dot product depends on coordinate system only through the chosen basis.
  • In complex spaces, use conjugate transpose (Hermitian inner product).

Example

If \(a=(1,2)\) and \(b=(3,4)\), then \(a\cdot b=11\).

How to Compute (Pseudocode)

Input: vectors x[1..n], y[1..n]
Output: dot product x . y

s <- 0
for i from 1 to n:
  s <- s + x[i] * y[i]
return s

Complexity

  • Time: \(O(n)\)
  • Space: \(O(1)\) extra space
  • Assumptions: Vectors have length \(n\); complex-valued vectors use a conjugate inner product convention

See also