CSCE 235
Homework
Assignment 8 (Programming) Solution
Assigned: March 13, 2009
Due: 12:30 p.m. March 30,
2009
(Homework 5
minutes late will not be accepted)
Since it is important for you to recognize whether a problem is a
permutation one, or a repetition one, or a combination one, and so on, the
following problems are not listed under particular topics.
1. (10 points) A DNA analysis has to deal with the four basic building blocks denoted as A, C, G, and T. Suppose that a problem requires one to build a DNA string with at most three building blocks, and must have at least one building block. How many ways are there to build such a string, assuming all combinations of building blocks are possible?
Solution
We divide
the problem into three smaller sub-problems: 1-building block strings,
2-building block strings, and 3-building block strings. For strings of only 1 building block, there
are only 4 ways (A, C, G, or T). For
strings of 2 building blocks, there are 4 ways to choose the first building block. Similarly, there are 4 ways to choose the
second building block. So there are (4)(4) = 16 ways to build a 2-building block string. Finally, with the similar reasoning process,
we have (4)(4)(4) = 64 ways to build a 3-building
block string. Altogether, there are thus
4 + 16 + 64 = 84 ways to build a DNA string with at most three building blocks,
and must have at least one building block.
2. (20 points) You are a photographer at a photo shop. A family of seven comes in to your shop: A grandpa, a grandma, a father, a mother, a daughter, and two sons. Now, you need to arrange them to sit in a row of chairs for the big photo shoot.
(a) If the grandpa and grandma must sit next to each other, how many ways are there to arrange the family?
(b) If the grandpa, father, and sons must sit together on one side, and the grandma, mother, and daughter must sit together on the other side, how many ways are there to arrange the family?
(c) If the grandpa and grandma must sit next to each other, the father must sit next to the grandpa, the mother must sit next to the grandma, how many ways are there to arrange the family?
(d) There seems to be a feud between the two sons and they insist to be sitting not next to each other. How many ways are there to arrange the family?
Solution
(a) If the grandpa and grandma must sit next to each other, how many ways are there to arrange the family?
Now, the grandpa (GP) and grandma (GM) sit next to each other. There are two ways to arrange them. Basically, GP-GM, or GM-GP. Since the grandparents sit next to each other, we can consider them as one single entity. So, now, we have left only the father (F), the mother (M), the daughter (D), the two sons (S1 and S2), and the grandparent combo to arrange. There are six items. So, we have 6! = 720 ways to arrange these six items. Since there are two ways for the grandparent combo, we have a total of (2)(720) = 1440 ways to arrange the family.
(b) If the grandpa, father, and sons must sit together on one side, and the grandma, mother, and daughter must sit together on the other side, how many ways are there to arrange the family?
So, let suppose we have a combo of all male family members as MC, and a combo of all female family members as FC. There are two ways to arrange these two combos, either MC-FC, or FC-MC. So we are set with that. Now, we need to figure out how many ways there are for the combo MC to exist, and for the combo FC to exist. There are four elements in MC. Thus, we have 4! = 24 ways to arrange the male family members on one side. Similarly, we have 3! = 6 ways to arrange the female family members on the other side. Since we are doing this in a sequence, we have (24)(6)(2) = 288 ways to arrange the family according to the above constraint.
(c) If the grandpa and grandma must sit next to each other, the father must sit next to the grandpa, the mother must sit next to the grandma, how many ways are there to arrange the family?
Using the same notation, we have combos like these: F-GP-GM-M or M-GM-GP-F. So there are two ways to arrange the four-member combo. Now, that means we have left three more members to arrange together with this 4-member combo. There are thus 4 items to arrange; and 4! = 24 ways, the four items. Thus, we have (24)(2) = 48 ways to arrange the family according to the above constraint.
(d) There seems to be a feud between the two sons and they insist to be sitting not next to each other. How many ways are there to arrange the family?
Now, we know that there are a total of 7! = 5040 ways of arranging the family for the photo shoot. If we can find out how many ways there are where the two sons sit next to each other, then we can subtract that number from the total number of ways, 5040. Now, for the two sons to sit next to each other, there are 1440 ways! How do we know this? This is exactly the same as our response to part (a). In part (a), the constraint requires us to put grandma and grandpa together; here to put the two sons together. It is the same. So, the number of ways to arrange the family so that the two sons do not sit next to each other is 5040 1440 = 3600.
3. (10 points) Suppose you are a Signal Specialist and you have been tasked to design flag signals for a communication protocol. To send a signal, you have to raise flags on some of the 10 sequentially positioned flagposts. You are only given three identical red flags, two identical blue flags, and two identical green flags. You must use all seven given flags in your signal. How many different signals do you have for the communication protocol? (Some flagposts will not have any flags, so, for example, the signal of R-R-Null-B-Null-B-G-G-R-Null is different from the signal of R-R-Null-Null-B-Null-B-G-G-R.)
Solution
This
is a combination problem. Basically, out
of 10 boxes (flagposts), where do you put the red
flags? For the first red flag, you have
10 options. For the second red flag, you
have 9 options. For the third red flag,
you have 8 options. Thus you have (10)(9)(8) = 720. But
since the red flags are identical, you divide by 3! = 6. Thus, you have 120. This is the same as 10 chooses 3 or
. Now, we have the
blue flags ad green flags to worry about.
We have seven positions left.
Thus, there are
ways to arrange the
blue flags. For the five positions left,
we have
ways to arrange the
green flags.
(Think About: What about the flagposts/positions with no flags?)
So, since this is a sequence, we also use the product/multiplication rule. Therefore, there is a total of (120)(21)(10) = 25200 ways to arrange the flags. So, you have 25200 different signals for your communication protocol.
4. (25 points) Suppose you are a communications code specialist. You have been given a task of coming up with codes for secured transmission. You are given 7 unique symbols: *, !, #, <, >, &, and %.
Solution
(a) (5 points) How many unique 5-symbol codes (with each symbol used at most once) are there?
This is P(7,5) = 7!/(7-5)! = 7!/2! = 2520.
(b) (5 points) How many unique 5-symbol codes (with each symbol used at most once) are there if * must be used?
Since * must be used, that leaves only four spots for the remaining 6 symbols. That is P(6,4) = 6!/(6-4)! = 6!/2! = 360. There are also five ways for the * to be placed in the code: in the first position, in the second position, etc. Thus, there are a total of 5*360 = 1800 unique 5-symbol codes.
(c) (5 points) How many unique 5-symbol codes (with each symbol used at most once) are there if the sequence <*> must be used?
In this case, we can treat <*> as a super-symbol. That gives us only four total symbols, and only 3 spots to be filled. That is P(4,3) = 4!/(4-3)! = 4! = 24.
(d) (5 points) How many unique 5-symbol codes (with each symbol used at most once) are there if * and ! cannot appear in the same code?
There are three scenarios:
(1) * is in the code but ! is not, (2) ! is in the code but * is not,
and (3) neither * nor ! is in the code.
For scenario 1, since * is used, that leaves only four spots for the
remaining 5 symbols (since we cannot use !).
There are P(5,4) ways for that. And since * can appear in five different
positions, the total number of ways is 5*P(5,4) =
5*(5!/1!) = 600 ways. Scenario 1 and
Scenario 2 are symmetric. For Scenario
3, we are left with only 5 symbols. The permutation is thus 5! = 120. Since all three scenarios are mutually
exclusive, we add them up: 600 + 600 + 120 = 1320 ways.
(e) (5 points) How many unique 5-symbol codes are there if each symbol can be used more than once?
Since each symbol can be
re-used, that means for each spot, there are 7 choices. Thus, we have 7*7*7*7*7 = 16807 ways.
![]()
5. (15 points) A car company advertises that customers could build the most customized cars from the company. For each customized car, there are 7 attributes. Each attribute has 3 choices. A customer has the flexibility to pick a specific choice for each attribute for the computer that he or she wants to build.
(a) How many ways are there to build a customized computer from the above company?
(b) After one month of operating, the company announces that it will arbitrarily remove 5 attributes (e.g., color, DVD options, seat cover options, etc.) from each customers picks and fix the values for these removed attributes at some default values to cut production costs. How many ways are there to build a customized car, now, from the above company based on the announcement?
Solution
(a) How many ways are there to build a customized computer from the above company?
Each attribute
has 3 choices. So, we have (3)(3)(3)···(3) =
= 2187 ways of building a customized car from the above
company.
(b) After one month of operating, the company announces that it will arbitrarily remove 5 attributes (e.g., color, DVD options, seat cover options, etc.) from each customers picks and fix the values for these removed attributes at some default values to cut production costs. How many ways are there to build a customized car, now, from the above company based on the announcement?
Now,
there are two stages here. First, we have to choose out of 7 attributes the 5
removed/defaulted attributes. There are
ways of doing that.
Second, for the remaining 2 attributes, there are
= 9 ways. There is a
total of 21*9 = 189 ways.
6. (10 points) In how many ways can 20 uniquely titled books be given to Tara, Danny, Shannon, and Mike so that one person has seven books, one has one book, and the other two people have six books each?
Solution
There
are two stages here. First, we want to
find out the number of ways in which the distribution of 7, 1, 6, and 6 can
happen. This is like a permutation with
4 letters in which two letters are the same (5). So, we have
ways of doing
that. Now, for the first person, there
are
ways of giving 7 books
to that person; for the second person, there are
ways of giving 1 book
to that person after giving away 6 books beforehand; for the third person,
there are
ways of giving 6 books
to that person, after giving away 8 books beforehand; and finally there is only
1 way to give 6 out of 6 books to the last person. So, there are
ways to for each
permutation. The total is thus
ways.
7. (10 points) Find the number of arrangements of the letters of each of the following words:
(a)
(b)
(c) RIOGRANDE
(d)
Solution
(a)
![]()
(b)
![]()
(c)
RIOGRANDE.
There are two Rs, and 9 letters. ![]()
(d)
![]()
8. (25 points) At a network testing site, there are five routers and a host. The host sends out messages to these five routers for relaying the message further. For your experiment, the host will send out only 5 messages. Each message is addressed to a particular router. However, you turn off the address reader of the host. So, basically, the messages are sent out blindly, one to each router.
(a) How many ways are there for every router to not receive its message correctly?
(b) How many ways are there for at least one router to receive its message correctly?
(c) How many ways are there for exactly one router to receive its message correctly?
(d) How many ways are there for at least 2 routers to receive their messages correctly?
(e) How many ways are there for at most 2 routers to receive their messages correctly?
Solution
(a) How many ways are there for every router to not receive its message correctly?
This is a
derangements problem. We have
. So, there are 44
ways for every router to not receive its message correctly.
(b) How many ways are there for at least one router to receive its message correctly?
In (a), we have solved for the cases in which 0 node receives its message correctly. Thus, if we find out how many ways the messages can be received, then we can simply subtract 44 out of that number to solve for this current question. So, there are 5 routers for the messages to go to; there are 5! = 120 ways of receiving the messages. Therefore, there are 120 44 = 76 ways for at least one router to receive its message correctly.
(c) How many ways are there for exactly one router to receive its message correctly?
So, one router
will receive its message correctly. That
means, we only have four messages left to be
de-arranged. So, now we have
. So, there are 9 ways
for the remaining routers to get their messages totally mixed up. Then we have to choose one router out of 5 to
be the router that receives its message correctly. That is
. Thus, we have a
total of (5)(9) = 45 ways in which exactly one router
to receive its message correctly.
(d) How many ways are there for at least 2 routers to receive their messages correctly?
Since we have solved for (b) and (c), we can get the answer for this question easily. We know that we have 76 ways in which at least router receives its message correctly, and there are 45 ways in which exactly one router receives its message correctly. Thus, there are 76 45 = 31 ways left for at least two routers receive their messages correctly.
(e) How many ways are there for at most 2 routers to receive their messages correctly?
We can break
this problem up into three mutually exclusive sub-problems: (1) 0 router
receives its message correctly there are 44 ways for this to happen, from our
solution to part (a); (2) 1 router receives its message correctly there are
45 ways for this to happen, from our solution to part (c); and (3) 2 routers
receive their messages correctly. To
compute the number of ways for third scenario to happen, we know that 2 routers
will get their messages correctly. So, three will be de-arranged: there are
ways for that to
happen. Now, we need to choose 2 out of
5 routers to be the ones that correctly receive their messages: there are
ways. Thus, we have a
total of (2)(10) = 20 ways in which exactly 2 routers
receive their messages correctly. Since
all the three scenarios/sub-problems are mutually exclusive, we can add them
up. Therefore, the
total number of ways in which at most 2 routers to receive their
messages correctly is 20 + 45 + 44 = 109.
9. (25 points) Suppose that you are the coach of your
local basketball camp for kids. There
are 25 kids in the camp with the following distribution:
|
Age Group |
Boys |
Girls |
Total |
|
8 years old |
3 |
4 |
7 |
|
9 years old |
5 |
4 |
9 |
|
10 years old |
8 |
1 |
9 |
|
Total |
16 |
9 |
25 |
(a) (5
points) How many ways are there to form a basketball
team of five players?
Solution
There are 25 players altogether to
choose 5 from:
![]()
(b) (5
points) How many ways are there to form a
basketball team of three boys and
two girls?
Solution
There are 16 boys and 9 girls. There are
to choose
three boys; and
to choose two
girls.
and
. Since it is a
sequence of events, we multiply them:
20160.
(c) (5 points) How
many ways are there to form a basketball team of five players with at least one
boy?
Solution
Lets find out how many ways there
are to form a team with all girls. That
is,
. So, the total number
of ways to form a team with at least one boy is then the total number of ways
minus 126: 53130 126 = 53004.
(d) (10 points) How many ways are there to
form a basketball team of five players with at
least one 8-year old, at least one 9-year
old, and at least one 10-year old?
Solution
First, let us figure out how many
types of teams we have. Say we denote
1-2-2 to indicate one 8-year old, two 9-year olds, and two 10-year olds on the
team. Then we have the following
combinations:
(1)
1-2-2
(2)
1-1-3
(3)
1-3-1
(4)
2-2-1
(5)
2-1-2
(6)
3-1-1
Case 1:
There are
ways.
Case 2:
There are
ways.
Case 3:
There are
ways.
Case 4:
There are
ways.
Case 5:
There are
ways.
Case 6:
There are
ways.
Since
these are mutually exclusive cases, we use the sum rule to add them up: 9072 +
5292 + 5292 + 6804 + 6804 + 2835 = 36099 ways.
![]()
10. (10 points) Use the Binomial Theorem to expand
. Simplify your
answer.
Solution
11. (20 points) Consider the binomial expansion of
.
Solution
(a) What are the first three terms?
The
first term is
. The second term is
. The third term is
.
(b) What are the last three terms?
The
last term is
. The second last term
is
. The third last term is
.
(c) What is the seventh term? The fifteenth term?
The
seventh term is
. The fifteenth term is
.
(d) What
is the coefficient of
?
The coefficient of
is
.
12. (25 points) Suppose that you are the Chief Technology Officer (CTO) of a computer game company. You are at a convention to present 8 different games newly released by your company. Seven (5) are different types of online simulation (S) games, and five (3) are different types of first-person shooter (F) games. Your task is to come up with a sequence of presenting these games in order to keep your audience interested. Your subordinates all suggest ideas on how to sequence these games. And too many ideas lead to too many options too quickly. Finally, as CTO, you would like to find out the following:
(a) How many ways are there to arrange these 8 games such that no first-person shooter games are presented next to each other?
(b) If the first and the last games of the presentation must be of the online simulation type, how many ways are there to arrange these 8 games?
(c) Suppose now that you decide that only five games will be presented. How many ways are there to choose and then sequence only five games?
(d) Assume that only games plants are to be presented. How many ways are there to choose and arrange these games such that there is at least one first-person shooter game?
Solution
(a) How many ways are there to arrange these 8 games such that no first-person player games are presented next to each other?
First, let us sequence the simulation games first. There are five of them. So, there are 5! ways of arranging them. As a result of this arrangement, now we have:
_ S _ S _ S _ S _ S _
So,
there are now 6 different spots for us to sequence the first-person shooter
games. That is, if we plant the first-person
shooter games in these spots, then we will be able to make sure that no two first-person
shooter games are next to each other.
So, there are 6 spots to choose three from to sequence three
first-person shooter games,
. Now, there are 3! ways
to arrange these three games. So, there
are in total
ways of arranging these 8 games such that no first-shooter
player games are sequenced next to each other.
(a) If the first and the last games of the presentation sequence must be of the online simulation type, how many ways are there to arrange these 8 games?
So, we want to have something like this:
S _ _ _ _ _ _ S
First,
we look at how many ways there are to select and arrange the first two online
simulation games, one as the first game and one as the last game. There are
ways. And, since the order is important, there are
twice as many ways: 20 ways in total.
(Alternatively, we could see that there are 5 ways to choose the first
rose, and then 4 ways to choose the last rose.
Thus, there are 20 ways.)
Now,
there are 3 simulation games and 3 first-player shooter games left to fill the
six spots in between the two games.
Since there are 6 different games, and the order is important, we have
6! ways to do so.
As a result, we have
ways
to arrange these 8 games.
(b) Suppose now that you decide that only five out of the eight given games will be presented. How many ways are there to choose and arrange only five games?
This
is simply P(8,5) =
ways. (Alternatively, we could see that
ways to choose five games to present. And then there are 5! ways
to arrange these five games. Thus, there
are
ways.)
(c) Assume that only five out of the eight given games are to be presented. How many ways are there to arrange these games such that there is at least one first-player shooter game?
We know the
total number of ways to arrange only five games, from (c): 6720 ways. So, if we find out the number of ways to
arrange five games such that NO first-player shooter game is presented, then we
can subtract that number from 6720 to obtain the result. To arrange five games without using a
first-player shooter game means that we present only all online simulation
games. There are 5 types. So, there are 5! ways
to arrange them,
Therefore,
there are
ways to arrange these games such
that there is at least one first-person shooter game.
![]()
Programming
13. (40 points) Tutorial. For this assignment, create a Web page that gives a tutorial on one of the following topics: permutations, combinations, repetitions, or derangements. For your tutorial, it must contain the following three items: (a) a detailed description of your topic and (b) one flash-animated exercise example.
For your flash-animated exercise example, you must use the following flash editor software, available for download at http://cse.unl.edu/~jhostetl/ife/. We have provided an HTML template for you for you to plug in the tutorial and the flash-animated example. If you have questions about the flash editor software, please contact Mr. Jesse Hostetler (jhostetl@cse.unl.edu), the chief designer and software developer of the software. Important Note: The software will be ready for download no later than March 23, 2009.
Note that this example is open-ended. Use your creativity and imagination to come up with a good flash-animated exercise example that best illustrate the topic of your choice.
Submit your html page and your flash file to the CSE handin as usual. We will then put all the pages online for all to visit.
Make your topic easy to understand and your exercise example meaningful. Be creative, be imaginative. While waiting for the flash editor software to become available, please spend some time thinking about what kind of exercise example that you would like to have.
Problems
based on (Goodaire and Parmenter
2002) and (Ross and Wright 1988).