ProblemYou are given a graph with n nodes (states) and the edges between them have probabilities associated with it. You are initially in state "start" and asked to calculate the probability/expectation of a "end" state

Solution

1) Build state graph (states as nodes and transitions as edges) from the description of problem statement. Identify the start states and end states.

2)

A) If the graph is a DAG (Directed Acyclic Graph) use Dynamic Programming to calculate the probability of values associated with required state.

B) If the graph is not a DAG and has cycles, build a set of equations describing the state transitions and use Gaussian Elimination to solve for the probability/expectation

Another approach is simulation. If desired accuracy of result is less for eg 1e-6 or so, simulate above transitions large number of times. The values should converge to actual values. This will work only if desired accuracy of result is less. For most accurate answer use Equation solving.

Description

Example 1 (Using Gaussian Elimination / Simulation) A manufacturer of a Chutes And Ladders game (also called Snakes and Ladders) wants to know what is the expected number of dice throws (6 sided ) to finish the game by a single person. If expected value is high user will get bored as it takes lot of time to finish. If it is less user will finish game quickly and lose interest. The board is given in input as an array t[] which denotes where a player will end if he reaches the cell i. If there is no chute or ladder at cell i, then t[i] = i , else it will be the cell where chute or ladder points to. Note : Here we are not looking at game as 2 player, but trying to evaluate how much time a single user will take to finish.

- States - Position of player position 0 .. n-1 where n is number of cells. Start state is 0 and end state is >= n-1 ( when user goes beyond last cell it is considered a finish)Transitions - Dice throw probability = p = 1/6. Additionally with the presence of chutes and ladders, user will move to other cells.

- This graph has cycles as based on chutes and ladders user can go back to previous cells. So build a set of equations and solve , say using Gaussian elimination

where i0 .. i5 are 6 states calculated from where player goes when dice shows 1 .. 6 as well as combining the fact where the resulting position has a chute or ladder While buidling the equation you might need to bring the non-constant terms of RHS of last relation to LHS (to make it a equation in standard form)

- Writing relation for each state above you will have n variables and n equations- Solve using Gaussian elimination and e[0] is the answer

- (i/n) probability that you will see already seen faces and (n-i)/n probability that you will see a unseen face at which seen count goes up by 1. - Since RHS has e[i], we can bring it to LHS and regrouping

e[i] = (n/(n-i) + e[i+1])

This now is a DAG and hence use DP to solve ie find all e[i], i in 0 .. n. Answer is e[0]

The topcoder community gathers the world's experts in design, development and data science to work on interesting and challenging problems for fun and reward. We want to help topcoder members improve their skills, demonstrate and gain reward for their expertise, and provide the industry with objective insight on new and emerging technologies.