VOOZH about

URL: https://www.geeksforgeeks.org/dsa/markov-matrix/

⇱ Program for Markov matrix - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program for Markov matrix

Last Updated : 20 Feb, 2023

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.

👁 Image
Example of Markov Matrix

Examples: 

Input :
1 0 0
0.5 0 0.5
0 0 1
Output : yes

Explanation :
Sum of each row results to 1, 
therefore it is a Markov Matrix.

Input :
1 0 0
0 0 2
1 0 0
Output : no

Approach : 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. 

Implementation:


Output
 yes 

Time Complexity: O(n2)
Auxiliary Space: O(1), since no extra space has been taken.

Comment
Article Tags: