There are 11 middlefielders in a football team. In how many ways 4 of them can be chosen to play in a match?
Solution: Combination rule since the order is not important. C(11,4) = 11!/(4!(11-4)!) = 330
#Combination Rule
choose(11,4)
## [1] 330
If we want to change the order of letters in the word “KELEBEK” how many of words with seven letters finish with “LEB”?
Solution: We are going to think about it like “_ _ _ _ L E B” Also remember the permutation rule with identical items. There are 2 “K”s and 3 “E”s. However, one of the “E” is in the “L E B” so we are going to take it “E”s as 2. The formula is n(number of spaces)! / n1!n2!…nk! So the result is: 4!/2!2! = 24/4 = 6
the_phrase <- "KELEBEK" #The word
freq_table <- table(strsplit(the_phrase,split="")[[1]]) #We are going to create a frequency table
print(freq_table)
##
## B E K L
## 1 3 2 1
the_phrase <- "KEKE" #Letters which we can put to spaces
freq_table <- table(strsplit(the_phrase,split="")[[1]]) # Frequency table for the usable letters
print(freq_table) #Let's show it
##
## E K
## 2 2
the_dividend <- factorial(nchar(the_phrase)) #Dividend part is 4 characters so 4!
the_divisor <- prod(factorial(freq_table)) #Get multiplication of factorials for the divisor
the_dividend/the_divisor
## [1] 6
The %40 of the students are girls in a class. %50 of boys and %70 of girls have failed. It is known that a randomly selected student in the class has passed the class. What is the probability of that student is a boy?
Solution: Remember that, probability is never greater than 1. Let’s say that the sum of boys and the girls in the class is 100. So 40 students are girls and only 12 of them have passed the class. This information also give us 60 students are boys and only 30 of them have passed the class. So the result is: 30/42 = 5/7 = 0.7142857
#We said that class is 100 people as an assumption.
n_student <- 100
n_girls <-40
n_boys <-60
#Let's find the number of boys who passed the class.
n_boys <- 60
the_dividend <-60
the_divisor <- 2 # Because only half of them passed the class
the_dividend/the_divisor
## [1] 30
#Let's find the number of girls who passed the class.
n_girls <- 40
the_ratio <- 30/100 # Because only %30 of them passed the class
n_girls*the_ratio
## [1] 12
n1 <- 30 #Number of boys who passed the class
n2 <- 12 #Number of girls who passed the class
n1/(n1+n2)
## [1] 0.7142857
n_players <- 12 #Number of teletubbies
factorial(n_players) #By permtuation it is 12!
## [1] 479001600
the_phrase <- "KUYRUKSALLAYANGILLER"
freq_table <- table(strsplit(the_phrase,split="")[[1]]) #Let's create a frequency table first
print(freq_table) #Let's show it
##
## A E G I K L N R S U Y
## 3 1 1 1 2 4 1 2 1 2 2
the_dividend <- factorial(nchar(the_phrase)) #Dividend part is 20 characters so 20!
the_divisor <- prod(factorial(freq_table)) #Get multiplication of factorials for the divisor
the_dividend/the_divisor
## [1] 1.055947e+15
#Combination function is choose for 3 seats in 34 seats.
choose(34,3)
## [1] 5984
#It is multiplication rule
n1 = 8 #In first place there can be 8 different teams.
n2 = 7 #In second place there can be 7 different teams not 8 because on of them will be in first place.
n3 = 6 #In third place there can be 6 different teams.
n1*n2*n3
## [1] 336
#Permutation rule
#9 red,3 yellow,6 black,7 blue
factorial(25)/(factorial(9)*factorial(3)*factorial(6)*factorial(7))
## [1] 1.963217e+12
#Combination rule
#c(9,5)*c(8,2)+c(9,6)*c(8,1)+c(9,7)*c(8,0)
#First option is 5 men and 2 women,second one is 6 men and 1 women,last option is 7 men and no women.
choose(9,5)*choose(8,2)+choose(9,6)*choose(8,1)+choose(9,7)*choose(8,0)
## [1] 4236
# The prime numbers are 2, 3 and 5 so;
n1=3 # number of ways it can happen
n2=6 #The Total number of outcomes
#Probability of an event happening = The Number of ways it can happen/The Total number of outcomes
n1/n2 # The probability of a prime number
## [1] 0.5
n1=5 # number of people who but a ticket
n2=3 # empty seats left
n3=3 #how many people you are chooseing at once
#(factorial(n1)*factorial(n2)) / (factorial(n3) * factorial(n1-n3))
choose(5,3)
## [1] 10
n1=7# number of red
n2=5 # number of blue
n3=9 # number of gren
n4= n1+n2+n3
(n1/n4) * (n2/(n4-1)) * (n3/(n4-2))
## [1] 0.03947368
Solution: nEvent/n1*n2 = 4/36
n1 <- 6 #die roll has six potential outcomes.
n2 <- 6 #die roll has six potential outcomes.
nEvent <- 4 #event of getting a sum which are (3,6) , (4,5) , (5,4) , (6,3).
nEvent/prod(n1,n2)
## [1] 0.1111111
Solution: Combination Rule!
n_clubmembers <- 4 #number of club members
n_comittee <- 4 #number of comittee which sould
n_men <- 20 #number of men
n_women <- 15 #number of women
n_ss <- choose(35,4) #Number of sample space
n_com <-choose(20,2) #Number of event of choosing 2 people from men
n_cow <-choose(15,2) #Number of event of choosing 2 people from women
prod(n_com,n_cow)/n_ss
## [1] 0.381016
Solution: Factorial!
the_phrase <- "ABCDE"
freq_table <- table(strsplit(the_phrase,split="")[[1]]) #Creating a frequency table in order to control repeating letters
print(freq_table) #Printing frequency table
##
## A B C D E
## 1 1 1 1 1
letter_length <- 3 #Number of letter words which we want create
n_ss <- factorial(nchar(the_phrase))/factorial(nchar(the_phrase)-letter_length) #Number of sample space
n_event <- 1 #Number of event which is "BAD"
print(n_event) #Printing event
## [1] 1
print(n_ss) #Printing sample space
## [1] 60
n_event/n_ss
## [1] 0.01666667
Solution: The sample space consists of 8 sample points.
A= {TTT, TTH, THT, THH, HTT, HTH, HHT, HHH}
Each sample point is equally likely to occur, so the probability of getting any particular sample point is 1/8. The event “getting two tails and one head” consists of the following subset of the sample space.
B = {TTH, THT, HTT}
The probability of Event B is the sum of the probabilities of the sample points in B. Therefore,
P(B)) = 1/8 + 1/8 + 1/8 = 3/8
#We are supposing that the coin is flipped 3 times.
#Permutation Rule
factorial(2)*factorial(2)*factorial(2)
## [1] 8
#Probability of the evet getting two tails and one head" .
n1 <- 1/8 #the probability of getting any particular sample point
n2 <- 1/8 #the probability of getting any particular sample point
n3 <- 1/8 #the probability of getting any particular sample point
(n1+n2+n3) #the total
## [1] 0.375
Students Solution: Calculate as if no rules.It is the combination of 50 to 10.Then remove the combinations of all Germany or all France or all Turkey people.
Instructor: Good question but wrong solution. So, what about 5 from France 5 from Turkey but no Germans? It is still not a valid combination. You have to take that into account.
Here is the solution. We might need to explicitly calculate German-Turkish, French-Turkish and German-French groups with the solo groups but remove solo groups from bi-country groups. Then subtract from all combinations.
All combinations \(C(All) = \binom{50}{10}\).
All Germans \(C(G) = \binom{15}{10}\), all Turkish \(C(T) = \binom{17}{10}\), all French \(C(F) = \binom{18}{10}\).
Only German-Turkish \(C(GT) = \binom{32}{10} - C(G) - C(T)\), only Turkish-French \(C(FT) = \binom{35}{10} - C(T) - C(F)\), only German-French \(C(GF) = \binom{33}{10} - C(F) - C(G)\).
Desired combinations \(C(Desired) = C(All) - C(G) - C(T) - C(F) - C(GT) - C(TF) - C(GF)\).
#Students solution
#Combination Rule
#choose(50,10)-choose(15,10)-choose(17,10)-choose(18,10)
n_german <- 15
n_turkish <- 17
n_french <- 18
n_total <- n_german + n_turkish + n_french
k <- 10
c_all <- choose(n_total,k)
c_t <- choose(n_turkish,k) #All Turkish
c_g <- choose(n_german,k)
c_f <- choose(n_french,k)
c_tg <- choose(n_turkish + n_german,k) - c_t - c_g # At least 1 German and 1 Turkish
c_tf <- choose(n_turkish + n_french,k) - c_t - c_f # At least 1 German and 1 Turkish
c_gf <- choose(n_french + n_german,k) - c_f - c_g # At least 1 German and 1 Turkish
c_all - c_t - c_g - c_f - c_tg - c_tf - c_gf
## [1] 9931691703
Solution: In order to be divided by 5, number must be end with 5 or 0. One of the most important points is that zero the number should not be placed as a first digit.Order is not important for the form so use combination.Last thing is to sum all of the possible outcomes.
Instructor’s note: It is actually permutation rule. Ordering is important because the number changes. Since your combination calculations .
#Combination Rule for 5 as a last digit; for 2 digits
n1 <- choose(4,1)+(choose(4,1)*choose(4,1))+(choose(4,1)*choose(4,1)*choose(3,1))
#Combination Rule for 0 as a last digit; for 2 digits
n2 <- choose(5,1)+(choose(5,1)*choose(4,1))+(choose(5,1)*choose(4,1)*choose(3,1))
#Let's sum all the possible outcomes.
n1+n2
## [1] 153