PHP Program for Markov matrix Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Given a m x n 2D matrix, check if it is a Markov Matrix.Markov Matrix: The matrix in which the sum of each row is equal to 1.Example of Markov MatrixExamples: Input :1 0 00.5 0 0.50 0 1Output : yesExplanation :Sum of each row results to 1, therefore it is a Markov Matrix.Input :1 0 00 0 21 0 0Output :noApproach: Initialize a 2D array, then take another single dimensional array to store the sum of each rows of the matrix, and check whether all the sum stored in this 1D array is equal to 1, if yes then it is Markov matrix else not. PHP <?php // PHP code to check Markov Matrix function checkMarkov($m) { $n = 3; // outer loop to access rows // and inner to access columns for ($i = 0; $i <$n; $i++) { // Find sum of current row $sum = 0; for ($j = 0; $j < $n; $j++) $sum = $sum + $m[$i][$j]; if ($sum != 1) return false; } return true; } // Driver Code // Matrix to check $m = array(array(0, 0, 1), array(0.5, 0, 0.5), array(1, 0, 0)); // calls the function check() if (checkMarkov($m)) echo " yes "; else echo " no "; // This code is contributed by nitin mittal. ?> Output yes Complexity Analysis:Time Complexity: O(m*n), Here m is the number of rows and n is the number of columns.Auxiliary Space: O(1), As constant extra space is used.Please refer complete article on Program for Markov matrix for more details! Create Quiz Comment K kartik Follow 0 Improve K kartik Follow 0 Improve Article Tags : PHP Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like