Matrix Operations

  1. Matrix addition. Given two matrices $A$ and $B$ of the same size, we add them element-wise and denote the result as $A + B$.

    Input: Two matrices $A_{n \times m}$ and $B_{n \times m}$.
    Output: $C = A + B$, where $c_{i,j} = a_{i,j} + b_{i,j}$.

    Algorithm:
    1. Create a matrix $C$ of size $n \times m$.
    2. For every $1 \le i \le n$, $1 \le j \le m$, set $c_{i,j} = a_{i,j} + b_{i,j}$. Then, return $C$.
    Runtime analysis: Counting additions and value assignments, we get a constant of $nm$, so the runtime is $\Theta(nm)$.