90 views
Consider two $n \times 1$ vectors $u$ and $v$ , stored as table $U(\text{ind,val})$ and $V(\text{ind,val})$ with the same schema A row $(i,u_i)$ of table $U$ specifies the $i^{th}$ element of vector $u$ has value $u_i$  (similarly for $v$, respectively). Only the non-zero entries of the vectors are stored in the corresponding tables. For example, if the vector $u$ equals $(0, 1, 3, 0, 2, 0)$, then it is represented in table $U$ as $$\begin{array}{|l|l|} \hline \textbf{ind}&\textbf{val} \\\hline 2&1 \\3&3 \\5&2\\ \hline \end{array}$$

Write a relational algebra expression or an SQL query to compute the sum $u + v$ of the two vectors $u$ and $v$. Explain your solution.

edited | 90 views