Given a Markov chain G, we have the find the probability of reaching the state F at time t = T if we start from state S at time t = 0.
A Markov chain is a random process consisting of various states and the probabilities of moving from one state to another. We can represent it using a directed graph where the nodes represent the states and the edges represent the probability of going from one node to another. It takes unit time to move from one node to another. The sum of the associated probabilities of the outgoing edges is one for every node.
Consider the given Markov Chain( G ) as shown in below image:
Input : S = 1, F = 2, T = 1 Output : 0.23 We start at state 1 at t = 0, so there is a probability of 0.23 that we reach state 2 at t = 1. Input : S = 4, F = 2, T = 100 Output : 0.284992
We can use dynamic programming and depth-first search (DFS) to solve this problem, by taking the state and the time as the two DP variables. We can easily observe that the probability of going from state A to state B at time is equal to the product of the probability of being at A at time and the probability associated with the edge connecting A and B. Therefore the probability of being at B at time is the sum of this quantity for all A adjacent to B.
Below is the implementation of the above approach:
The probability of reaching 2 at time 100 after starting from 4 is 0.284992
Time complexity: O(N2 * T)
Space complexity: O(N * T)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Finding the probability of a state at a given time in a Markov chain | Set 2
- Minimum time to return array to its original state after given modifications
- Word Ladder (Length of shortest chain to reach a target word)
- Difference between Distance vector routing and Link State routing
- Three-State Bus Buffers
- A matrix probability question
- Maximizing Probability of one type from N containers
- Find minimum value of y for the given x values in Q queries from all the given set of lines
- Find time taken for signal to reach all positions in a string
- Find time taken to execute the tasks in A based on the order of execution in B
- MakeMyTrip Interview Experience | Set 13 (On-Campus for Full Time)
- Minimum time taken by each job to be completed given by a Directed Acyclic Graph
- Disjoint Set (Or Union-Find) | Set 1 (Detect Cycle in an Undirected Graph)
- Find the number of Islands | Set 2 (Using Disjoint Set)
- Find all reachable nodes from every node present in a given set
- Find if an undirected graph contains an independent set of a given size
- Find integral points with minimum distance from given set of integers using BFS
- Minimum value possible of a given function from the given set
- Check if the given array can be constructed uniquely from the given set of subsequences
- Minimum time required to rot all oranges
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.