# Bus Problems

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.

## 6 thoughts on “Bus Problems”

1. cool-RR says:

Hey dude. Your blog is quite interesting, if you feel like talking, 8237158 on ICQ. bye, Ram.

2. Quite entertaining, I think. There’s something about knowing what you should do when you get to the bus stop that makes the entire process that much easier. Maybe that’s why I walk so much…
Oh, and as a special bonus, the answer to the second question was answered in a slightly different way by another friend of mine, “You just ride your bike, it’s easier.” <wryly smiles>

Have Fun.

3. Fergal Daly says:

I think you’ve overcomplicated the 2nd case in the bus-toilet problem. All you’re doing is going to the bathroom then waiting for a bus then sitting on a bus. The expected waiting-for-bus time does not depend on the state of your bladder (despite how you might feel) and so the sum is β + T/2 + λ

4. Luke Palmer says:

Indeed I have, and I’m well aware of that. There is nothing the least time dependent in this problem, so there is no way to explain the large asymmetry between going to the bathroom before or after the bus ride. Of course, it’s always easier to simplify the problem once you know the answer (indeed, look at the second problem: we could have just compared the expectations and been done, right?). When I came up with this problem, however, I didn’t know the answer. I thought that it would be better to go afterward, because if you go beforehand, you might miss the bus. Mathematically, everything evens out, but it’s hard to know that a priori, especially if you’re expecting it not to.

5. Matt says:

Problem is, you’re silently assuming an exponential distribution for bus waiting times, but real-life buses often have correlated waiting times due to bunching phenomena, service disruptions etc. So in practice there is usually a strategy which involves some kind of cut-off point at which you stop waiting and start walking.

6. Matt says:

Actually you may be silently assuming something more general than that – perhaps some kind of independence condition. I’m not sure exactly. With these things it helps to spell out exactly what are the random variables and what are their assumed distributions, or else sloppy reasoning can take hold.