Counting AssinmentRi
Counting AssinmentRi
Submitted To:
Joyassree Sen
Associate Professor
Department of Computer Science & Engineering
Islamic University, Bangladesh
Submitted By:
Ferdous Ara Rimi
Roll:23140051
Reg:230011121
Session:2023-24
Department of Computer Science and Engineering
Islamic University, Bangladesh
Introduction to Counting
Counting is an essential aspect of discrete mathematics, playing a
crucial role in combinatorics, probability theory, algorithm analysis, and
computer science. It provides a foundation for solving problems related
to arrangements, selections, and distributions. The ability to count
efficiently using mathematical principles helps in optimization and
problem-solving in multiple domains.
EXAMPLE
A new company with just two employees, Sanchez and Patel, rents a
floor of a building with 12 offices. How many ways are there to assign
different offices to these two employees?
THE SUM RULE: If a task can be done either in one of n1 ways or in one
of n2 ways, where none of the set of n1 ways is the same as any of the
set of n2 ways, then there are n1 + n2 ways to do the task.
EXAMPLE
A student can choose a computer project from one of three lists. The
three lists contain 23, 15, and 19 possible projects, respectively. No
project is on more than one list. How many possible projects are there
to choose from?
Example
THE DIVISION RULE: There are n/d ways to do a task if it can be done
using a procedure that can be carried out in n ways, and for every way
w, exactly d of the n ways correspond to way .
Example
How many ways can we seat 4 students in a row if two of them are
identical twins?
Solution:
4!/2!=24/2=12
Tree Diagrams
EXAMPLE
Suppose that “I Love New Jersey” T-shirts come in five different sizes:
S, M, L, XL, and XXL. Further suppose that each size comes in four
colors, white, red, green, and black, except for XL, which comes only in
red, green, and black, and XXL, which comes only in green and black.
How many different shirts does a souvenir shop have to stock to have
at least one of each available size and color of the T-shirt?
Solution: The tree diagram in Figure 4 displays all possible size and
color pairs. It follows that the souvenir shop owner needs to stock 17
different T-shirts.
FIGURE 2: Counting Varieties of T-Shirts
EXAMPLE: Suppose that there are eight runners in a race. The winner
receives a gold medal, the second-place finisher receives a silver medal,
and the third-place finisher receives a bronze medal. How many
different ways are there to award these medals, if all possible
outcomes of the race can occur and there are no ties?
Combinations:
C(n, r) =
EXAMPLE: How many ways are there to select five players from a 10-
member tennis team to make a trip to a match at another school?
= + +···+ ,
Where:
The merge sort algorithm splits a list to be sorted with n items, where n
is even, into two lists with n/2 elements each, and uses fewer than n
comparisons to merge the two sorted lists of n/2 items each into one
sorted list. Consequently, the number of comparisons used by the
merge sort to sort a list of n elements is less than M(n), where the
function M(n) satisfies the divide-and-conquer recurrence relation
M(n) = 2M(n/2) + n.
f (n) = f (n/2) + 2
when n is even.
f (n) = af (n/b) + c
f (n) is O( ) if a < ,
f (n) is O( log n) if a = ,
f (n) is O( ) if a >
Inclusion–Exclusion
∣A∪B∣=∣A∣+∣B∣−∣A∩B∣
∣A∣: Size of set A.
∣B∣: Size of set B.
∣A∩B∣: Size of the intersection of A and B.
∣A∪B∪C∣=∣A∣+∣B∣+∣C∣−∣A∩B∣−∣A∩C∣−∣B∩C∣+∣A∩B∩C∣
∣ ∪ ∪⋯∪ ∣=∑ −∑ ∑
−⋯+ ∣ |
Applications of Inclusion–Exclusion:
∣A∪B∣=∣A∣+∣B∣−∣A∩B∣=4+4−2=6
Conclusion