Combinatorial Counting and Algorithm Design Concepts

 
CS 173, Lecture B
Tandy Warnow
 
 
Topics for today
 
Basics of combinatorial counting
Applications to running time analysis
 
Using combinatorial counting
 
Evaluating exhaustive search
strategies:
Finding maximum clique
Determining if a graph has a 3-coloring
Finding a maximum matching in a graph
Determining if a graph has a Hamiltonial
cycle or an Eulerian graph
 
Combinatorial counting
 
How many ways can you
put n items in a row?
pick k items out of n?
pick subsets of a set of size n?
assign k colors to the vertices of a graph?
match up n boys and n girls?
 
Technique
 
To count the number of objects, design
an algorithm to generate the entire set
of objects.  Check if each object is
created exactly once (if not, you will
have to do a correction later).
The algorithm’s output can be seen as
the leaves of a decision tree, and you
can just count the leaves.
 
Putting n items in a row
 
Algorithm for generating all the possibilities:
For i=1 up to n, DO
Pick an item from S to go in position i
Delete that item from the set S
Analysis: each way of completing this generates
a different list.
T
h
e
 
n
u
m
b
e
r
 
o
f
 
w
a
y
s
 
o
f
 
p
e
r
f
o
r
m
i
n
g
 
t
h
i
s
a
l
g
o
r
i
t
h
m
 
i
s
 
n
!
 
Number of subsets of a set of
size n
 
Algorithm to generate the subsets of a set
S = {s
1
, s
2
, s
3
, …, s
n
}
For i=1 up to n DO:
Decide if you will include s
i
 
Analysis: each subset is generated
exactly once, and the number of ways
to apply the algorithm is 2x2x…x2=2
n
.
 
k-coloring a graph
 
Let G have vertices v
1
, v
2
, v
3
, …, v
n
 
Algorithm to k-color the vertices:
For i=1 up to n DO:
Pick a color for vertex v
i
 
Analysis: each coloring is produced exactly
once, and there are k
n
 ways of applying the
algorithm.
 
Matching n boys and girls
 
Algorithm:
Let the boys be B
1
, B
2
, … B
n
 and let the girls
be G
1
, G
2
, … G
n
.
For i=1 up to n DO
Pick a girl for boy B
i
, and remove her from the set
Analysis: there are n ways to pick the first girl,
n-1 ways to pick the second girl, etc., and
each way produces a different matching.
Total:  n!
 
Picking k items out of n
 
Algorithm for generating all the possibilities:
For i=1 up to k, DO
Pick an item from S to include in set A
Delete that item from the set S
 
The number of ways of performing this
algorithm is n(n-1)(n-2)…(n-k+1)=n!/(n-k)!
But each set A can be generated in multiple
ways - and we have overcounted!
 
Fixing the overcounting
 
 
Each set A of k elements is obtained through k! ways of
running the algorithm. As an example, we can
generate {s
1
, s
5
, s
3
} in 6 ways, depending upon the
order in which we pick each of the three elements.
So the number of different sets is the number of ways of
running the algorithm, divided by k!.
T
h
e
 
s
o
l
u
t
i
o
n
 
i
s
 
n
!
/
[
k
!
(
n
-
k
)
!
]
 
Summary (so far)
 
To count the number of objects, design
an algorithm to generate the entire set
of objects.  Check if each object is
created exactly once (if not, you will
have to do a correction later).
The algorithm’s output can be seen as
the leaves of a decision tree, and you
can just count the leaves.
 
Summary
 
Number of orderings of n elements is n!
Number of subsets of n elements is 2
n
Number of k-subsets of n elements is
n!/[k!(n-k)!]
Number of k-colorings of a graph is k
n
 
More advanced counting
 
What is the number of k-subsets of a set S =
{s
1
, s
2
, s
3
, … , s
n
} that do not include s
1
?
What is the number of k-subsets of a set S =
{s
1
, s
2
, s
3
, … , s
n
} that do include s
1
?
What is the number of orderings of the set S
in which s
1
 and s
2
 are not adjacent?
What is the number of orderings of the set S
in which s
1
 and s
2
 are adjacent?
 
New techniques
 
Count the complement
Divide into disjoint cases, and count
each case
 
Example
 
What is the number of k-subsets of a
set S = {s
1
, s
2
, s
3
, … , s
n
} that do not
include s
1
?
Solution: same as number of k-subsets
of {s
2
, s
3
, … , s
n
}.  So (n-1)!/[(n-1-k)!k!]
 
Example
 
What is the number of k-subsets of a
set S = {s
1
, s
2
, s
3
, … , s
n
} that do
include s
1
?
Solution: same as the number of (k-1)-
subsets of {s
2
, s
3
, … , s
n
}, so
 
(n-1)!/[(n-k)!(k-1)!]
 
Example
 
What is the number of orderings of the set S
in which s
1
 and s
2
 are adjacent?
 
Solution: two cases:
Case 1) s
1
 followed by s
2
Case 2) s
2
 followed by s
1
Same number of each type.  Easy to see that
there are (n-1)! of each type, so 2(n-1)! in
total
 
Example
 
Number of orderings of the set S in
which s
1
 and s
2
 are not adjacent?
 
This is the same as n!-2(n-1)!
 
Using combinatorial counting
 
Evaluating exhaustive search
strategies:
Finding maximum clique
Determining if a graph has a 3-coloring
Finding a maximum matching in a graph
Determining if a graph has a Hamiltonian
cycle or an Eulerian tour
Slide Note
Embed
Share

Today's lecture covers the basics of combinatorial counting and its applications in algorithm analysis. Topics include exhaustive search strategies, determining graph properties, and various counting techniques. Techniques such as counting objects and generating subsets are discussed, along with algorithms for tasks like coloring graphs and matching individuals. The aim is to develop an understanding of how to count and analyze different objects systematically, leading to efficient algorithm design.

  • Combinatorial Counting
  • Algorithm Design
  • Graph Theory
  • Decision Trees
  • Counting Techniques

Uploaded on Nov 27, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CS 173, Lecture B Tandy Warnow

  2. Topics for today Basics of combinatorial counting Applications to running time analysis

  3. Using combinatorial counting Evaluating exhaustive search strategies: Finding maximum clique Determining if a graph has a 3-coloring Finding a maximum matching in a graph Determining if a graph has a Hamiltonial cycle or an Eulerian graph

  4. Combinatorial counting How many ways can you put n items in a row? pick k items out of n? pick subsets of a set of size n? assign k colors to the vertices of a graph? match up n boys and n girls?

  5. Technique To count the number of objects, design an algorithm to generate the entire set of objects. Check if each object is created exactly once (if not, you will have to do a correction later). The algorithm s output can be seen as the leaves of a decision tree, and you can just count the leaves.

  6. Putting n items in a row Algorithm for generating all the possibilities: For i=1 up to n, DO Pick an item from S to go in position i Delete that item from the set S Analysis: each way of completing this generates a different list. The number of ways of performing this algorithm is n!

  7. Number of subsets of a set of size n Algorithm to generate the subsets of a set S = {s1, s2, s3, , sn} For i=1 up to n DO: Decide if you will include si Analysis: each subset is generated exactly once, and the number of ways to apply the algorithm is 2x2x x2=2n.

  8. k-coloring a graph Let G have vertices v1, v2, v3, , vn Algorithm to k-color the vertices: For i=1 up to n DO: Pick a color for vertex vi Analysis: each coloring is produced exactly once, and there are knways of applying the algorithm.

  9. Matching n boys and girls Algorithm: Let the boys be B1, B2, Bnand let the girls be G1, G2, Gn. For i=1 up to n DO Pick a girl for boy Bi, and remove her from the set Analysis: there are n ways to pick the first girl, n-1 ways to pick the second girl, etc., and each way produces a different matching. Total: n!

  10. Picking k items out of n Algorithm for generating all the possibilities: For i=1 up to k, DO Pick an item from S to include in set A Delete that item from the set S The number of ways of performing this algorithm is n(n-1)(n-2) (n-k+1)=n!/(n-k)! But each set A can be generated in multiple ways - and we have overcounted!

  11. Fixing the overcounting Each set A of k elements is obtained through k! ways of running the algorithm. As an example, we can generate {s1, s5, s3} in 6 ways, depending upon the order in which we pick each of the three elements. So the number of different sets is the number of ways of running the algorithm, divided by k!. The solution is n!/[k!(n-k)!]

  12. Summary (so far) To count the number of objects, design an algorithm to generate the entire set of objects. Check if each object is created exactly once (if not, you will have to do a correction later). The algorithm s output can be seen as the leaves of a decision tree, and you can just count the leaves.

  13. Summary Number of orderings of n elements is n! Number of subsets of n elements is 2n Number of k-subsets of n elements is n!/[k!(n-k)!] Number of k-colorings of a graph is kn

  14. More advanced counting What is the number of k-subsets of a set S = {s1, s2, s3, , sn} that do not include s1? What is the number of k-subsets of a set S = {s1, s2, s3, , sn} that do include s1? What is the number of orderings of the set S in which s1and s2are not adjacent? What is the number of orderings of the set S in which s1and s2are adjacent?

  15. New techniques Count the complement Divide into disjoint cases, and count each case

  16. Example What is the number of k-subsets of a set S = {s1, s2, s3, , sn} that do not include s1? Solution: same as number of k-subsets of {s2, s3, , sn}. So (n-1)!/[(n-1-k)!k!]

  17. Example What is the number of k-subsets of a set S = {s1, s2, s3, , sn} that do include s1? Solution: same as the number of (k-1)- subsets of {s2, s3, , sn}, so (n-1)!/[(n-k)!(k-1)!]

  18. Example What is the number of orderings of the set S in which s1and s2are adjacent? Solution: two cases: Case 1) s1followed by s2 Case 2) s2followed by s1 Same number of each type. Easy to see that there are (n-1)! of each type, so 2(n-1)! in total

  19. Example Number of orderings of the set S in which s1and s2are not adjacent? This is the same as n!-2(n-1)!

  20. Using combinatorial counting Evaluating exhaustive search strategies: Finding maximum clique Determining if a graph has a 3-coloring Finding a maximum matching in a graph Determining if a graph has a Hamiltonian cycle or an Eulerian tour

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#