CPSC 327 Data Structures and Algorithms Spring 2024

Homework 24
due Wed 4/17 in class

For each of the following, develop an efficient dynamic programming algorithm using the 16-step dynamic programming development process discussed in class.

  1. A shuffle S of two strings A and B is formed by interleaving the characters of A and B without changing their order. For example, three possible shuffles of hello and goodbye are hellogoodbye, hgeololdobye, and gohoeldblyoe. However, geoodlblohye is not a shuffle because the h is out of order with respect to the other characters of A. Given strings A, B, and S, determine whether S is a shuffle of A and B. Note that the characters of A and B do not need to be unique - it is fine for the same letter to appear in both strings. It will then appear multiple times in S.

  2. In sporting events where the outcome depends on the results of several games (such as World Series in baseball or the Stanley Cup in hockey), there are always statistics about how likely it is for a team that is down some number of games to win it all. The championship series problem is defined as follows: two teams A and B are playing a series of games in which the first team to win n games is the winner. Assume that team A has a probability of p of winning any given game (meaning that team B has a probability of 1-p of winning the game). Suppose that some number of games have already been played, where team A has won i of them and team B has won j. (Assume that ties are not allowed.) Determine the probability that A will go on to win the series.

    Math refresher: the probability that two independent events X and Y will both occur is the probability of X occurring multiplied by the probablity of Y occurring. That's why, for example, the probability of flipping heads twice in a row is 1/4 - 1/2 for the first head times 1/2 for the second head. Furthermore, the probability that either X or Y will occur is the probablity of X occurring plus the probability of Y occurring.