Matrix Operations
- Inner product. Given two vectors, compute the sum of pairwise products. We also call an inner product a dot product and a linear combination.
Input: Vectors $u, v \in \mathbb{R}^n$ (meaning, each of $u$ and $v$ has $n$ real elements in it.) Usually, $u$ (the leftmost one) is a row vector, and $v$ (the rightmost one) is a column vector.
Output: $s = \sum_{i=1}^n (u_i \cdot v_i)$. The figure $s$ is just a number/scalar.
Algorithm:
- Set $s=0$.
- For each $1 \le i \le n$, set $s = s + u_i \cdot v_i$. Then, return $s$.
Runtime analysis: $\Theta(n)$. This is because we do $n$ multiplications and $n-1$ additions (and $n$ index increments), which results in $n + (n - 1) + n =$$\; 3n - 1 =$$\; \Theta(n)$.