FInding maximum in matrix
Difference between en1 and en2, changed 10 character(s)
Suppose, I have a matrix with N rows and M columns. I want to find the number that appears most along with their frequencies for each row and each column. If there are multiple such numbers, any of them will do.↵

For example, let the matrix be a 4*3 matrix like this:↵

9 4 4 ↵

5 4 2↵

1 3 1↵

1 1 2↵

then I will perform calculation in these four arrays as follows:↵

rowval = {4,2,1,1} [ith value denotes the number that appears most in ith row]↵

rowfrq = {2,1,2,2} [the number of time the the max value of ith row appears]↵

colval = {1,4,2} [ith value denotes the number that appears most in ith column]↵

colfrq = {2,2,2} [the number of time the the max value of ith column appears]↵

What will be the most efficient way of performing this calculation? N*M can be upto 10^6 and the values of the matrix can be upto 10^6 as well . I was thinking of using map, but cannot understand what the complexity will be. Of course if there is a better approach, please help :) ↵

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English sore_loser 2016-02-08 20:25:20 10
en1 English sore_loser 2016-02-08 20:24:39 1002 Initial revision (published)