An integer matrix is said to be sparse if more than half of its entries is 0. Define an ML function sparse which checks whether a square matrix is sparse. (You can assume that the input will be a square matrix.)

An integer matrix is said to be sparse if more than half of its entries is 0. Define an ML function
sparse which checks whether a square matrix is sparse. (You can assume that the input will be a
square matrix.)
You may define auxiliary functions. (Hint: Define a function that counts how many times a particular
value occurs in a list.)
For instance,

  • sparse;
    val it = fn : int list list → bool
  • sparse [];
    val it = false : bool
  • sparse [[]];
    val it = false : bool
  • sparse [[1,0], [0,1]];
    val it = false : bool
  • sparse [[1,2,3], [0,0,1], [0,0,0]];
    val it = true : bool
  • sparse [[1,2,3], [0,0,1], [0,0,4]];
    val it = false : bool
  • sparse [[1,0,0,0], [0,1,0,0], [0,0,2,0], [~3,0,0,2]];
    val it = true : bool

Is this a proposal for a new ML exercise?