Carleton University
Department of Systems and Computer Engineering
SYSC 2002 - Winter 2009

Assignment 7

Dick and Jane were walking home one day. Being a baseball fan, Jane mused, “I wonder what the chances are of the Angels winning the World Series in seven games”. Dick doesn’t care about sports, but is a bit of an egghead. “That’s easy”, he said, “the probability of the Angels winning in seven games is equal to the probability of the series being tied at 3-3 times the probability of the Angels winning the seventh game.” Jane laughed. “Oh, but you’re so silly! That’s no answer at all. What’s the probability of the series being tied 3-3?” “Simple”, Dick replied, “the probability of the series being tied 3-3 is equal the probability of the Angels losing 2-3 times the probability of them winning the sixth game, plus the probability of the Giants losing 2-3 times the probability of them winning the sixth game”. Jane was getting exasperated. “But you’re just chasing your tail”, she said, “This could go on forever”. “I don’t think so”, Dick replied. “I’m pretty certain that the series will start out tied 0-0”.

For those who don’t know about it, the “World” Series is a best of seven baseball championship. The two teams involved play until one of them has won four games, at which point that team wins the championship. We’ve put “World” in quotation marks because, in reality, the series is an exclusively North American affair. Indeed it has been an almost purely American event, though Toronto has appeared twice, winning both times. A few years ago the series was between the Anaheim Angels and the San Francisco Giants. (See "Some Clarifications" below for more information.)

Write and test a RECURSIVE function that returns the probability that, at some point in the series, the Angel will have won “i” times and the Giants will have won “j” times. Dick and Jane’s conversation should suggest the correct approach. If “i” is 4 and “j” is 3, the function should return the correct answer to Jane’s original question.

Two files are supplied. Including “odds.h” in your program and “odds.cpp” in your project will give you access to a function called “probabilityOfAngelVictory”. It returns the probability of the Angels winning the “nth” game. Note that the probability of the Giants winning the “nth” game is one minus the probability of the Angels winning it. Note too that this exercise deals with mathematical probabilities and not with percentages. Probability values will always be between between 0 (impossible) and 1 (certain).

Test your function by writing a main function that uses it to produce a table showing the probabilities of all possible series outcomes (Angels in 4 games, Giants in 4 games, Angels in 5 games, and so on). Submit a single file (called series.cpp) containing your function and your test code.

Food for Thought (optional): Once you’ve got your things working, add a global counter (OK just this once!) thatis initialized to zero and which is incremented every time that your recursive function is called with “i” and “j” both equal to zero. (Note that Dev-C++ requires that global variables start with a "_", i.e. underscore.) Write a short test main function which simply calls your function with “i” equal to 4 and “j” equal to 3, and then outputs the value of this counter. Think about what is going on. Can you think of a better approach involving a 2D array such that array[i,j] is the probability that, at some point in the series, the Angels will have won “i” times and the Giants will have won “j” times?

Some Clarifications

It is not necessary to know anything about baseball to do this assignment. All you need to know is that each game has a winner and a loser (no ties allowed). If you prefer you can imagine that the games are hockey or football or flipping coins or any other game with two teams (or players).

A “best of seven” series is a sequence of 7 games used to determine the best team. The best (winning) team is the one that wins the most games. As a team cannot lose once they’ve won 4 games (the most the other team can win is 3), the series ends when one team has won 4 games. Thus the series could last anywhere from 4 (minimum) to 7 (maximum) games.

To say that team “A” wins in 5 games means that team “B” won just one of the first four games and team “A” won #5 (so the series ended there). There are four possible ways that this could happen. Here we are using “A” to represent a win by “A” and “B” to represent a win by “B”. Each row represents one possible series that ends with “A” winning in 5 games. A A A B A (i.e. “B” wins only the 4th game) A A B A A (i.e. “B” wins only the 3rd game) A B A A A (i.e. “B” wins only the 2nd game) B A A A A (i.e. “B” wins only the 1st game) Note that the sequence “A A A A B” is not listed. Why?

Below Jane asks what the chances are of the Angels winning the World Series in 7 games. This means that the Angels and Giants must each win 3 of the first 6 games (so the series is tied 3-3) and then the Angels win #7. There are lots of possible game sequences that lead to this result and the recursive definition below allows you to find them all.

If you want to know more (though it is not necessary to solve this assignment) about the World Series or other best of seven series, here are some web sites that may be of interest: http://mlb.mlb.com/mlb/ps/y2006/index.jsp, http://www.whowins.com/, http://www.aip.org/isns/reports/2003/080.html, and http://en.wikipedia.org/wiki/World_Series.

Updated: Sunday, February 22nd, 2009.