Check if a given matrix is sparse or not | PHP code to check if a matrix is sparse . ; Count number of zeros in the matrix ; Driver Code
< ? php $ MAX = 100 ; function isSparse ( $ array , $ m , $ n ) { $ counter = 0 ; for ( $ i = 0 ; $ i < $ m ; ++ $ i ) for ( $ j = 0 ; $ j < $ n ; ++ $ j ) if ( $ array [ $ i ] [ $ j ] == 0 ) ++ $ counter ; return ( $ counter > ( ( $ m * $ n ) / 2 ) ) ; } $ array = array ( array ( 1 , 0 , 3 ) , array ( 0 , 0 , 4 ) , array ( 6 , 0 , 0 ) ) ; $ m = 3 ; $ n = 3 ; if ( isSparse ( $ array , $ m , $ n ) ) echo " Yes " ; else echo " No " ; ? >