Matrix Operations
- Matrix transpose. We take matrix $A_{n \times m}$ and generate another matrix $A^T_{m \times n}$ (
A^T_{m \times n}
), called $A$'s transpose, by exchanging rows with columns.
Input: Any matrix $A_{n \times m} = [a_{i,j}]$.
Output: The matrix $A^T_{m \times n} = [a^T_{j,i}]$.
Algorithm:
- Create an empty matrix container $A^T = [a^T_{j,i}]$ of the size $m \times n$ ($m$ rows and $n$ columns).
- For every $1 \le j \le m$ and every $1 \le i \le n$, set $a^T_{j,i} = a_{i,j}$. Then, return $A^T$.
Runtime analysis:
In the 1st step, creating the matrix double array will take $\Theta(nm)$ operations. In the 2nd step, we will do $\Theta(nm)$ element assigments. In total, we will have $\Theta(nm) + \Theta(nm) =$$\; c_1nm + c_2nm =$$\; (c_1 + c_2)nm =$$\; \Theta(nm)$ operations.