0% found this document useful (0 votes)
17 views13 pages

Counting AssinmentRi

The document is an assignment on counting in discrete mathematics, detailing fundamental principles such as the product rule, sum rule, subtraction rule, and division rule. It also covers advanced techniques like recurrence relations, generating functions, and the inclusion-exclusion principle, providing examples for each concept. The importance of counting in fields like computer science and probability is emphasized throughout.

Uploaded by

rahatakanda47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views13 pages

Counting AssinmentRi

The document is an assignment on counting in discrete mathematics, detailing fundamental principles such as the product rule, sum rule, subtraction rule, and division rule. It also covers advanced techniques like recurrence relations, generating functions, and the inclusion-exclusion principle, providing examples for each concept. The importance of counting in fields like computer science and probability is emphasized throughout.

Uploaded by

rahatakanda47
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Department of Computer Science and Engineering

Assignment On: Counting


Course Title: Discrete Mathematics
Course Code: CSE 1101

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.

The Basics of Counting


Counting is one of the fundamental concepts in discrete mathematics,
used to determine the number of ways an event can occur. It forms the
basis for probability, combinatorics, and algorithm analysis. We first
present two basic counting principles, the product rule and the sum
rule and two complement counting principles, the subtraction rule and
the division rule.

THE PRODUCT RULE: Suppose that a procedure can be broken down


into a sequence of two tasks. If there are n1 ways to do the first task
and for each of these ways of doing the first task, there are n2 ways to
do the second task, then there are n1n2 ways to do the procedure.

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?

Solution: The procedure of assigning offices to these two employees


consists of assigning an office to Sanchez, which can be done in 12
ways, then assigning an office to Patel different from the office
assigned to Sanchez, which can be done in 11 ways. By the product
rule, there are 12 · 11 = 132 ways to assign 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?

Solution: The student can choose a project by selecting a project from


the first list, the second list, or the third list. Because no project is on
more than one list, by the sum rule there are 23 + 15 + 19 = 57 ways to
choose a project.

THE SUBTRACTION RULE: If a task can be done in either n1 ways or n2


ways, then the number of ways to do the task is n1 + n2 minus the
number of ways to do the task that are common to the two different
ways.

Example

How many numbers between 1 and 100 are not divisible by 5?


Solution:

Total numbers: 100

Numbers divisible by 5: 100 ÷ 5 = 20

Numbers not divisible by 5: 100−20=80

So, there are 80 numbers that are not divisible by 5.

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:

Without identical twins: 4! = 24

Since the twins are identical, we divide by 2! = 2:

4!/2!=24/2=12

Thus, there are 12 unique seating arrangements.

Tree Diagrams

Counting problems can be solved using tree diagrams. A tree consists of


a root, a number of branches leaving the root, and possible additional
branches leaving the endpoints of other branches. To use trees in
counting, we use a branch to represent each possible choice. We
represent the possible outcomes by the leaves, which are the endpoints
of branches not having other branches starting at them.

FIGURE 1: Best Three Games Out of Five Playoffs

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

Permutations and Combinations


Permutations:

A permutation is an arrangement of objects in a specific order. The


order of selection matters in permutations.

 If n is a positive integer and r is an integer with 1 ≤ r ≤ n, then


there are P (n, r) = n(n − 1)(n − 2) · · · (n − r + 1)

r- permutations of a set with n distinct elements.

 If n and r are integers with 0 ≤ r ≤ n, then P (n, r) =

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?

Solution: The number of different ways to award the medals is the


number of 3-permutations of a set with eight elements. Hence, there
are P (8, 3) = 8 · 7 · 6 = 336 possible ways to award the medals.

Combinations:

A combination is a selection of objects where the order does not


matter.

 The number of r-combinations of a set with n elements, where n


is a nonnegative integer and r is an integer with 0 ≤ r ≤ n, equals

C(n, r) =

 Let n and r be nonnegative integers with r ≤ n.


Then C(n, r) = C(n, 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?

Solution: The answer is given by the number of 5-combinations of a set


with 10 elements. By

Theorem 2, the number of such combinations is


C(10, 5) = = 252.
Advanced Counting Techniques
Advanced counting techniques extend basic counting principles to solve
more complex combinatorial problems. These techniques are widely
used in combinatorics, computer science, and algorithm analysis. Some
important advanced counting techniques include:

Applications of Recurrence Relations

A recurrence relation is an equation that expresses each term of a


sequence as a function of its preceding terms. It is commonly used in
algorithm analysis and combinatorial problem-solving.

Example Recurrence Relations:

 The Fibonacci sequence:

 The recurrence relation for the Tower of Hanoi problem:


,

Solving Linear Recurrence Relations

A linear homogeneous recurrence relation of degree k with constant


coefficients is a recur-

rence relation of the form

= + +···+ ,

where , ,..., , are real numbers, and ≠ 0.


Divide-and-Conquer Algorithms and Recurrence Relations

Divide-and-Conquer is a problem-solving approach where a problem is


divided into smaller sub problems, solved recursively, and combined to
obtain the final result. Recurrence relations are used to analyze their
time complexity.

General Recurrence Relation:

f (n) = af (n/b) + g(n).

Where:

 a is the number of sub problems created.


 b is the factor by which the problem size reduces.
 g(n) is the time taken for dividing and combining.

Example 1: Merge Sort

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.

Example 2: Binary Search

This binary search algorithm reduces the search for an element in a


search sequence of size n to the binary search for this element in a
search sequence of size n/2, when n is even. (Hence, the problem of
size n has been reduced to one problem of size n/2.) Two comparisons
are needed to implement this reduction (one to determine which half
of the list to use and the other to determine whether any terms of the
list remain). Hence, if f (n) is the number of comparisons required to
search for an element in a search sequence of size n, then

f (n) = f (n/2) + 2

when n is even.

MASTER THEOREM: Let f be an increasing function that satisfies the


recurrence relation

f (n) = af (n/b) + c

whenever n = , where k is a positive integer, a ≥ 1, b is an integer


greater than 1, and c and d are real numbers with c positive and d
nonnegative. Then

f (n) is O( ) if a < ,

f (n) is O( log n) if a = ,

f (n) is O( ) if a >

Example: Complexity of Merge Sort

In Example 2 we explained that the number of comparisons used


by the merge sort to sort a list of n elements is less than M(n), where
M(n) = 2M(n/2) + n.
By the master theorem, we find that M(n) is O(n log n),
Generating Functions

Generating functions are a powerful tool in combinatorics, used to


represent sequences as power series.

The generating function for the sequence , ...... of real


numbers is the infinite series

G(x) = + +···+ +···=∑

Inclusion–Exclusion

The Inclusion-Exclusion Principle is a fundamental concept in


combinatorics and probability theory. It is used to calculate the
probability or count of the union of multiple sets by including and
excluding overlapping elements. Here's a detailed explanation:

The principle provides a way to calculate the size of the union of


multiple sets by:

 Including the sizes of individual sets.


 Excluding the sizes of their pairwise intersections.
 Including the sizes of triple intersections, and so on, alternating
between inclusion and exclusion.

1.Formula for Two Sets

For two sets A and B:

∣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.

2. Formula for Three Sets

For three sets A, B, and C:

∣A∪B∪C∣=∣A∣+∣B∣+∣C∣−∣A∩B∣−∣A∩C∣−∣B∩C∣+∣A∩B∩C∣

The formula alternates between inclusion and exclusion to account for


overlaps.

3. General Formula for n Sets

For n sets , ,…, :

∣ ∪ ∪⋯∪ ∣=∑ −∑ ∑
−⋯+ ∣ |

Applications of Inclusion–Exclusion:

 Counting Problems: Calculate the number of elements in


the union of sets.
 Probability: Find the probability of the union of events.
 Number Theory: Solve problems related to divisibility and
coprime numbers.
 Combinatorics: Solve problems involving permutations,
combinations, and derangements.

Example 1: Two Sets

 Let A ={ 1,2,3,4} and B={3,4,5,6}


 ∣A∣=4 , ∣B∣=4 , and ∣A∩B∣=2.
 Using the inclusion-exclusion principle:

∣A∪B∣=∣A∣+∣B∣−∣A∩B∣=4+4−2=6

The union A∪B={1,2,3,4,5,6}A∪B={1,2,3,4,5,6} has 6 elements.

Conclusion

Counting is an essential mathematical tool applied in various fields such


as computer science, probability, and cryptography. Understanding
different counting techniques enables solving complex combinatorial
problems efficiently.

You might also like