How to find the average number of iterations for a variable to reach a number. Suppose I have an infinite loop with a variable x that starts at 0. Every iteration of the loop, x has a 10% chance of being increased by 1 and a 90% chance of being decreased by 1, but it cannot go below 0. How can I calculate the average number of iterations of the loop for x to reach a certain number?

Tyson Atkins

Tyson Atkins

Answered question

2022-10-15

How to find the average number of iterations for a variable to reach a number.
Suppose I have an infinite loop with a variable x that starts at 0. Every iteration of the loop, x has a 10% chance of being increased by 1 and a 90% chance of being decreased by 1, but it cannot go below 0. How can I calculate the average number of iterations of the loop for x to reach a certain number?

Answer & Explanation

broeifl

broeifl

Beginner2022-10-16Added 11 answers

Step 1
As per MSE protocol, I can't give a full answer, but just to start you off, suppose you want to know the expected # of steps to get to 4 on the natural number line from 0,
we can start by writing S 0 = 1 + 0.1 S 1 + 0.9 S 0
Step 2
This equation means that with one step from 0, we either move with P r = 0.1 to step 1 or fall back to step 0 (since we can't go below 0) with P r = 0.9, and we can frame similar equations step by step, so the four equations will be
S 0 = 1 + 0.1 S 1 + 0.9 S 0
S 1 = 1 + 0.1 S 2 + 0.9 S 0
S 2 = 1 + 0.1 S 3 + 0.9 S 1
S 3 = 1 + 0.9 S 2

Do you have a similar question?

Recalculate according to your conditions!

New Questions in High school probability

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?