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 :) ↵
↵
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 :) ↵



