matrix - Calculate highest row sum in efficient way -


hi trying solve 1 problem. have m*n matrix. integer matrix 0 , 1 only.i want find out row sum of elements highest. solve simple solution. using 2 loops , calculating sum of each row. want find more efficient way this. 1 have idea it. need optimized solution. thank you.

let's consider 2 elements in different rows of matrix. pick two, doesn't matter ones long not in same row. set every other element of matrix zero. can choose row answer writing 1 in 1 of our chosen elements , 0 in other.

what says me in worst case, no matter how clever are, may have examine o(m*n) elements of matrix in order find 1 has sole non-zero value. can never have better worst-case running time o(m*n).

but can short-circuit procedure in cases. suppose far, highest sum of elements in row have examined far x. examining new row containing n elements. if, time have examined k of elements, sum of k elements less x - n + k, know sure sum of elements in row less x, , not need @ row further.

this algorithm still o(mn) in worst case, under reasonable assumptions contents of matrix, mean (average) running time less naive algorithm applied same matrix. can done parallel processing, although think lead more steps (on average), albeit divided on more processors. is, i'd expect "speedup factor" less number of processors used.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -