There are two mathematical problems of interest that came to mind the other day while I was waiting for the bus to school. One is of my own curiosity, the other belongs to my friend. They were not difficult to solve, but the results were fun. I think they would make excellent problems for a college algebra class, once the students are familiar with the concept of “expectation”.
Problem 1: Let’s say there’s a bus that comes every T minutes
(but you don’t know the schedule), and it takes λ minutes to get to get to school once you get on the bus. Also assume that it takes β time to go to the bathroom. You would like to minimize your expectation to go to the bathroom and get to school; that is, if you were to do this a million times, you want to minimize the sum of all the times you did it. The question is: do you go to the bathroom before or after the bus ride?
Problem 2: Again, the bus comes every T minutes, and it takes λ minutes to get to your destination riding the bus. It takes w minutes to walk to your destination from the bus stop. The problem as phrased to me was: once you get to the bus stop, how long do you wait before you start walking?
Solutions follow (you might try to work at least the first one out by yourself, for fun).
For Problem 1: let’s introduce a random variable α representing the time when the bus actually comes, defining time=0 to be the beginning of the problem. Of course, the bus will come again at time T+α. Let’s look at what happens when we go to the bathroom after the bus ride:
time = α + λ + β, so the expectation is e = T/2 + β + λ.
That was easy. Now let’s look at what happens if you go to the bathroom beforehand. If the bus comes while you’re going to the bathroom, you have to wait for it to come again.
If α < β (probability: β/T), then e = β/2 + T + λ. (We say β/2 because we know the bus came while we were going to the bathroom)
Otherwise (probability: 1 – β/T), e = (T+β)/2 + λ
Finding the total expectation is just the linear combination of the expectations weighted by the probabilities: (β/T)(β/2 + T + λ) + (1-β/T)((T+β)/2 + λ) = T/2 + β + λ
Oh my, that’s the same as we got before. It seems that it doesn’t matter when you go to the bathroom. My initial goal was to find out that you should go to the bathroom afterward, since you might miss the bus beforehand. But the math says different, and here is my explanation: when you go beforehand and you don’t miss the bus, you’re spending the time you would have been using to wait for the bus to do another task. If you wait until after the trip, you’re spending the time no matter how long you waited. It just happens to balance out perfectly numerically.
For Problem 2: Let’s call the time you decide to start walking s. We’re going to compute the expectation for all s in [0,T), and try to minimize that value. As we did before, let’s break it up into cases on α (the time that the bus actually comes):
If α < s (probability s/T), then e = s/2 + λ.
Otherwise (probability 1-s/T), e = s + w.
Now, let’s do our weighted combination: e = (s/T)(s/2 + λ) + (1-s/T)(s+w). This expands to a quadratic in s: e = -s2/2T – ws/T + λs/T + s + w. The most notable thing is that the second-order term is negative, so this parabola opens downward. That means that our minimum is going to occur at the “edges” of the plot, not somewhere in the middle. This is important already. It means that when you arrive at the bus stop, you calculate whether you are going to walk or wait, and then stick with the plan. You never wait a certain amount of time and then start walking.
Now, let’s find the values at the edges:
When s = 0 (you decide to walk): e = w.
When s = T (you decide to wait): e = T/2 + λ
So you walk whenever w < T/2 + λ. Look what you’re comparing. You’re comparing the dumb expectations for each one. If you walk, you will definitely get there in w minutes; if you wait, you’ll get there on average in T/2 + λ minutes. So we went through all this complicated math, checking all possible “start walking times”, and we found the obvious. These are the kinds of problems I love. I guess I also like the ones where the answer is subtle and unexpected. Let’s just leave it at the conclusion that I like cool math problems.