Object-Oriented Programming · Bloomberg · Easy
Build a class that represents a sparse one-dimensional array. Its logical length is n, yet only m of its positions hold a nonzero value, where n is far larger than m. The class must support these methods: get(index): return the value stored at index, or 0 when nothing is stored there. set(index, value): overwrite the value at index. dot(other): compute the dot product with another sparse array of the same length, i.e. $$\sum_i \text{self}[i] \cdot \text{other}[i]$$. Both…