# CMPSCI 311: Theory of Algorithms

### Fall, 2003

Here are questions and answers on HW#7, due 21 November 2003. Questions are in black, answers in blue.

##### Question 5, 20 November 2003

B7.1- the Greek symbol (gamma?) a, and b in the last paragraph suddenly appear with no referencing. What are they? I hope thy determine transition.

That's a delta, and it does represent the transition function of the DFA. delta(q,a) is the state the dfa goes into if it is in state q and sees an a.

#### Question 4, 20 November 2003

Q8.1.9- Thanks to Jeff's help, I can generate a table of all possible win/loss combinations and p's chance of winning from each position.In b) you are to calculate the series probability. The only way I could think of using this table was to average all of the table entries; this assumes that all possibilities are equally likely, which I am could argue both ways about. It also comes out to 0.4, the chance of winning one game, which....could make sense, but I am not thrilled about it.

8.1.9.c) I assumed the pseudocode was to generate the table, but it could be about calculating the series odds. ??

(from Jeff)

(a) Your task is to set up a recurrence equation like we discussed in
office hours today.  It should look similar to this:
base cases      P(i,0) = ?, P(0,j) = ?
recursive case  P(i,j) = some function of cases you will have already
calculated (remember we spoke about analyzing
just 1 game from state P(i,j) and then
recursing to other states)

(b) Your job is to figure out the probably of team A winning the series
before a game has even been played.  Thus, they are asking for P(4,4).
At the beginning of a 7 game series, both teams need to win four games to
win it all.

(c) Your pseudocode should work for any  given to it.  So think
of your code as a method with parameters .  In the course of the
code, you will create a table to determine the value P(i,j) given the
probability of team A winning = p.  Thus you will return P(i,j) at the end
of the method.

#### Question 3, 19 November 2003

8.4.1b) I'm not exactly sure what Levitin means by "different optimal subsets." Does he mean the number of times during the course of running the algorithm that the algorithm was confronted with the choice of two subsets that were both optimal for the question it is currently considering?

No, I think he means the number of acceptable-weight sets of items that achieve the maximum possible value, i.e., that are tied for being the optimal set of items.

8.4.1c) I'm assuming Levitin means strictly having only the table. (i.e. we run the algorithm and get a table back but don't have access to any information during the algorithm's run).

Yes, i think you're right.

#### Question 2, 18 November 2003

I am stuck on Q 8.4.1. I did fine with part (a) but what I don't understand is what "optimal subsets" mean in part (b) and (a). Can you clarify that?

The goal of the knapsack problem is to find a set of items that fits in the sack (has an acceptable weight sum) and has the greatest possible value sum. This is what an optimal subset is. There may be more than one optimal subset if more than one subset has the same value sum and they all have acceptable weight sums. That is, more that one set is tied for the best value sum.

#### Question 1, 17 November 2003

When I follow the code on page 278 to solve 8.1.4, I keep getting 1, which seems wrong. I think there is a typo in the code.

Yes, "if j=0 or j=k" should be "if j=0 or j=i".