Select entries having the requested column. The representation invariant ensures that the selected list has length at most one.ConsequentlyThis version follows the hint and has time complexity linear in the number of stored entries in row
def get(i: Int, j: Int): Double = {
require(0 <= i && i < N && 0 <= j && j < N)
val entries = rows(i).filter(e => e._1 == j)
if (entries.isEmpty) 0.0 else entries.head._2
}i. An ordered early-exit scan is also possible. Articles by others on the same topic
There are currently no matching articles.