Counting CS1200, CSE IIT Madras Meghana Nasre March 26, 2020 - - PowerPoint PPT Presentation

counting
SMART_READER_LITE
LIVE PREVIEW

Counting CS1200, CSE IIT Madras Meghana Nasre March 26, 2020 - - PowerPoint PPT Presentation

Counting CS1200, CSE IIT Madras Meghana Nasre March 26, 2020 CS1200, CSE IIT Madras Meghana Nasre Counting Counting (without counting) Basic Counting Techniques Pigeon Hole Principle (revisited) Permutations and Combinations


slide-1
SLIDE 1

Counting

CS1200, CSE IIT Madras Meghana Nasre March 26, 2020

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-2
SLIDE 2

Counting (without counting)

  • Basic Counting Techniques
  • Pigeon Hole Principle (revisited)
  • Permutations and Combinations
  • Combinatorial Identities

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-3
SLIDE 3

Pigeonhole principle

A surprisingly simple principle with varied applications. Also known as Dirichlet drawer principle.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-4
SLIDE 4

Pigeonhole principle

A surprisingly simple principle with varied applications. Also known as Dirichlet drawer principle. For a positive integer k, if k + 1 objects are placed into k boxes, then there is at least one box with two or more objects.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-5
SLIDE 5

Pigeonhole principle

A surprisingly simple principle with varied applications. Also known as Dirichlet drawer principle. For a positive integer k, if k + 1 objects are placed into k boxes, then there is at least one box with two or more objects. Note: This does not mean that every box contains at least one object. In fact, many boxes may be left empty.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-6
SLIDE 6

Pigeonhole principle

A surprisingly simple principle with varied applications. Also known as Dirichlet drawer principle. For a positive integer k, if k + 1 objects are placed into k boxes, then there is at least one box with two or more objects. Note: This does not mean that every box contains at least one object. In fact, many boxes may be left empty. Generalization: If N objects are placed in k boxes then there is at least one box containing at least N

k

  • bjects.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-7
SLIDE 7

Pigeonhole principle

A surprisingly simple principle with varied applications. Also known as Dirichlet drawer principle. For a positive integer k, if k + 1 objects are placed into k boxes, then there is at least one box with two or more objects. Note: This does not mean that every box contains at least one object. In fact, many boxes may be left empty. Generalization: If N objects are placed in k boxes then there is at least one box containing at least N

k

  • bjects.

Qn: If a drawer contains red, blue, green and black socks, how many socks should you pull out (without looking at the socks) so that you are guaranteed a pair (of some color)?

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-8
SLIDE 8

Pigeonhole principle

A surprisingly simple principle with varied applications. Also known as Dirichlet drawer principle. For a positive integer k, if k + 1 objects are placed into k boxes, then there is at least one box with two or more objects. Note: This does not mean that every box contains at least one object. In fact, many boxes may be left empty. Generalization: If N objects are placed in k boxes then there is at least one box containing at least N

k

  • bjects.

Qn: If a drawer contains red, blue, green and black socks, how many socks should you pull out (without looking at the socks) so that you are guaranteed a pair (of some color)? Sol: Note that if we are lucky we can get a pair by pulling two socks.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-9
SLIDE 9

Pigeonhole principle

A surprisingly simple principle with varied applications. Also known as Dirichlet drawer principle. For a positive integer k, if k + 1 objects are placed into k boxes, then there is at least one box with two or more objects. Note: This does not mean that every box contains at least one object. In fact, many boxes may be left empty. Generalization: If N objects are placed in k boxes then there is at least one box containing at least N

k

  • bjects.

Qn: If a drawer contains red, blue, green and black socks, how many socks should you pull out (without looking at the socks) so that you are guaranteed a pair (of some color)? Sol: Note that if we are lucky we can get a pair by pulling two socks. However, in the worst case, we may pull out 4 socks and all of them may be of different

  • colors. Thus if we pull out 5 or more socks, we will always be guaranteed a pair
  • f some color.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-10
SLIDE 10

Example 1

Qn: Consider the integers 1, 2, 3, . . . , 8 and let us select any 5 integers from this set. The goal is to show that there is a pair of integers that sum upto 9.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-11
SLIDE 11

Example 1

Qn: Consider the integers 1, 2, 3, . . . , 8 and let us select any 5 integers from this set. The goal is to show that there is a pair of integers that sum upto 9.

Try some examples.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-12
SLIDE 12

Example 1

Qn: Consider the integers 1, 2, 3, . . . , 8 and let us select any 5 integers from this set. The goal is to show that there is a pair of integers that sum upto 9.

Try some examples. Say 1, 3, 6, 7, 8. Yes, there is a pair (3, 6)

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-13
SLIDE 13

Example 1

Qn: Consider the integers 1, 2, 3, . . . , 8 and let us select any 5 integers from this set. The goal is to show that there is a pair of integers that sum upto 9.

Try some examples. Say 1, 3, 6, 7, 8. Yes, there is a pair (3, 6) and in fact another pair (1, 8).

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-14
SLIDE 14

Example 1

Qn: Consider the integers 1, 2, 3, . . . , 8 and let us select any 5 integers from this set. The goal is to show that there is a pair of integers that sum upto 9.

Try some examples. Say 1, 3, 6, 7, 8. Yes, there is a pair (3, 6) and in fact another pair (1, 8). Before you see the proof, think about what are the holes and what are the pigeons

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-15
SLIDE 15

Example 1

Qn: Consider the integers 1, 2, 3, . . . , 8 and let us select any 5 integers from this set. The goal is to show that there is a pair of integers that sum upto 9.

Try some examples. Say 1, 3, 6, 7, 8. Yes, there is a pair (3, 6) and in fact another pair (1, 8). Before you see the proof, think about what are the holes and what are the pigeons

Sol: Note that every integer from 1, 2, . . . , 8 has a unique “partner” which ensures that their sum is 9. Lets make four holes, one per pair. Now since we select 5 integers there is at least one hole in which both the elements of the pair are selected. This completes the proof.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-16
SLIDE 16

Example 1

Qn: Consider the integers 1, 2, 3, . . . , 8 and let us select any 5 integers from this set. The goal is to show that there is a pair of integers that sum upto 9.

Try some examples. Say 1, 3, 6, 7, 8. Yes, there is a pair (3, 6) and in fact another pair (1, 8). Before you see the proof, think about what are the holes and what are the pigeons

Sol: Note that every integer from 1, 2, . . . , 8 has a unique “partner” which ensures that their sum is 9. Lets make four holes, one per pair. Now since we select 5 integers there is at least one hole in which both the elements of the pair are selected. This completes the proof. Ex: In our example selection, we saw two pairs. Can we strengthen our claim that there are always two pairs that sum upto 9? If yes, modify the proof. If no, construct a counter example.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-17
SLIDE 17

Example 2

Qn: There are 51 houses on a street. Each house has a distinct number between 1000 and 1099, both inclusive. Show that there are at least two houses that have numbers which are consecutive integers.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-18
SLIDE 18

Example 2

Qn: There are 51 houses on a street. Each house has a distinct number between 1000 and 1099, both inclusive. Show that there are at least two houses that have numbers which are consecutive integers.

Before you see the proof, think about what are the holes and what are the pigeons.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-19
SLIDE 19

Example 2

Qn: There are 51 houses on a street. Each house has a distinct number between 1000 and 1099, both inclusive. Show that there are at least two houses that have numbers which are consecutive integers.

Before you see the proof, think about what are the holes and what are the pigeons.

Sol: There are 100 total addresses, lets have 50 holes so that each hole corresponds to two consecutive addresses. That is, 1000, 1001 are one hole and so on.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-20
SLIDE 20

Example 2

Qn: There are 51 houses on a street. Each house has a distinct number between 1000 and 1099, both inclusive. Show that there are at least two houses that have numbers which are consecutive integers.

Before you see the proof, think about what are the holes and what are the pigeons.

Sol: There are 100 total addresses, lets have 50 holes so that each hole corresponds to two consecutive addresses. That is, 1000, 1001 are one hole and so on. Now since there are 51 houses, there is at least one hole containing two houses, implying that there are at least two houses with consecutive integers as their numbers. This completes the proof.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-21
SLIDE 21

A clever application of the principle

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-22
SLIDE 22

Example 3: Increasing / decreasing subsequences

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-23
SLIDE 23

Example 3: Increasing / decreasing subsequences

We are given a sequence of N distinct integers

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-24
SLIDE 24

Example 3: Increasing / decreasing subsequences

We are given a sequence of N distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-25
SLIDE 25

Example 3: Increasing / decreasing subsequences

We are given a sequence of N distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6

  • In general the sequence is a1, a2, . . . , aN.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-26
SLIDE 26

Example 3: Increasing / decreasing subsequences

We are given a sequence of N distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6

  • In general the sequence is a1, a2, . . . , aN.
  • A subsequence of the above sequence is of the form ai1, ai2, . . . , aik where

1 ≤ i1 < i2 < . . . < ik ≤ N.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-27
SLIDE 27

Example 3: Increasing / decreasing subsequences

We are given a sequence of N distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6

  • In general the sequence is a1, a2, . . . , aN.
  • A subsequence of the above sequence is of the form ai1, ai2, . . . , aik where

1 ≤ i1 < i2 < . . . < ik ≤ N. For example S1 = 5, 3, 2, 8 is a subsequence of the above sequence. Another subsequence is S2 = 3, 8, 15.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-28
SLIDE 28

Example 3: Increasing / decreasing subsequences

We are given a sequence of N distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6

  • In general the sequence is a1, a2, . . . , aN.
  • A subsequence of the above sequence is of the form ai1, ai2, . . . , aik where

1 ≤ i1 < i2 < . . . < ik ≤ N. For example S1 = 5, 3, 2, 8 is a subsequence of the above sequence. Another subsequence is S2 = 3, 8, 15.

  • A subsequence is called strictly increasing if each term is larger than the
  • ne preceding it.

S1 is not strictly increasing, however S2 is strictly increasing.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-29
SLIDE 29

Example 3: Increasing / decreasing subsequences

We are given a sequence of N distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6

  • In general the sequence is a1, a2, . . . , aN.
  • A subsequence of the above sequence is of the form ai1, ai2, . . . , aik where

1 ≤ i1 < i2 < . . . < ik ≤ N. For example S1 = 5, 3, 2, 8 is a subsequence of the above sequence. Another subsequence is S2 = 3, 8, 15.

  • A subsequence is called strictly increasing if each term is larger than the
  • ne preceding it.

S1 is not strictly increasing, however S2 is strictly increasing.

  • A subsequence is called strictly decreasing if each term is smaller than

the one preceding it. S1 and S2 are both not strictly decreasing.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-30
SLIDE 30

Example 3: Increasing / decreasing subsequences

We are given a sequence of N distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6

  • In general the sequence is a1, a2, . . . , aN.
  • A subsequence of the above sequence is of the form ai1, ai2, . . . , aik where

1 ≤ i1 < i2 < . . . < ik ≤ N. For example S1 = 5, 3, 2, 8 is a subsequence of the above sequence. Another subsequence is S2 = 3, 8, 15.

  • A subsequence is called strictly increasing if each term is larger than the
  • ne preceding it.

S1 is not strictly increasing, however S2 is strictly increasing.

  • A subsequence is called strictly decreasing if each term is smaller than

the one preceding it. S1 and S2 are both not strictly decreasing. Qn: Identify a decreasing subseq. in the given sequence.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-31
SLIDE 31

Example 3: Increasing / decreasing subsequences

We are given a sequence of N distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6

  • In general the sequence is a1, a2, . . . , aN.
  • A subsequence of the above sequence is of the form ai1, ai2, . . . , aik where

1 ≤ i1 < i2 < . . . < ik ≤ N. For example S1 = 5, 3, 2, 8 is a subsequence of the above sequence. Another subsequence is S2 = 3, 8, 15.

  • A subsequence is called strictly increasing if each term is larger than the
  • ne preceding it.

S1 is not strictly increasing, however S2 is strictly increasing.

  • A subsequence is called strictly decreasing if each term is smaller than

the one preceding it. S1 and S2 are both not strictly decreasing. Qn: Identify a decreasing subseq. in the given sequence. Does every sequence have an increasing as well as decreasing subsequence?

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-32
SLIDE 32

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-33
SLIDE 33

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Our goal: To show that either a “large” increasing subsequence or a “large” decreasing subsequence exists.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-34
SLIDE 34

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Our goal: To show that either a “large” increasing subsequence or a “large” decreasing subsequence exists. Some remarks

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-35
SLIDE 35

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Our goal: To show that either a “large” increasing subsequence or a “large” decreasing subsequence exists. Some remarks

  • What is large?

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-36
SLIDE 36

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Our goal: To show that either a “large” increasing subsequence or a “large” decreasing subsequence exists. Some remarks

  • What is large? We say n + 1 is large for an input sequence of length n2 + 1.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-37
SLIDE 37

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Our goal: To show that either a “large” increasing subsequence or a “large” decreasing subsequence exists. Some remarks

  • What is large? We say n + 1 is large for an input sequence of length n2 + 1.
  • Note that in our example n2 + 1 = 32 + 1 = 10 that is, we are interested

in 4 length subsequences.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-38
SLIDE 38

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Our goal: To show that either a “large” increasing subsequence or a “large” decreasing subsequence exists. Some remarks

  • What is large? We say n + 1 is large for an input sequence of length n2 + 1.
  • Note that in our example n2 + 1 = 32 + 1 = 10 that is, we are interested

in 4 length subsequences.

  • Is there a 4 length increasing subsequence?

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-39
SLIDE 39

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Our goal: To show that either a “large” increasing subsequence or a “large” decreasing subsequence exists. Some remarks

  • What is large? We say n + 1 is large for an input sequence of length n2 + 1.
  • Note that in our example n2 + 1 = 32 + 1 = 10 that is, we are interested

in 4 length subsequences.

  • Is there a 4 length increasing subsequence? Yes! 5, 8, 12, 15.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-40
SLIDE 40

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Our goal: To show that either a “large” increasing subsequence or a “large” decreasing subsequence exists. Some remarks

  • What is large? We say n + 1 is large for an input sequence of length n2 + 1.
  • Note that in our example n2 + 1 = 32 + 1 = 10 that is, we are interested

in 4 length subsequences.

  • Is there a 4 length increasing subsequence? Yes! 5, 8, 12, 15.
  • Is there a 4 length deceasing subsequence?

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-41
SLIDE 41

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Our goal: To show that either a “large” increasing subsequence or a “large” decreasing subsequence exists. Some remarks

  • What is large? We say n + 1 is large for an input sequence of length n2 + 1.
  • Note that in our example n2 + 1 = 32 + 1 = 10 that is, we are interested

in 4 length subsequences.

  • Is there a 4 length increasing subsequence? Yes! 5, 8, 12, 15.
  • Is there a 4 length deceasing subsequence? Yes! 5, 3, 2, 1.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-42
SLIDE 42

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Our goal: To show that either a “large” increasing subsequence or a “large” decreasing subsequence exists. Some remarks

  • What is large? We say n + 1 is large for an input sequence of length n2 + 1.
  • Note that in our example n2 + 1 = 32 + 1 = 10 that is, we are interested

in 4 length subsequences.

  • Is there a 4 length increasing subsequence? Yes! 5, 8, 12, 15.
  • Is there a 4 length deceasing subsequence? Yes! 5, 3, 2, 1.
  • Finally, note the or. That is, we are content with either a large increasing

subsequence or a large decreasing subsequence.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-43
SLIDE 43

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Our goal: To show that either a “large” increasing subsequence or a “large” decreasing subsequence exists. Some remarks

  • What is large? We say n + 1 is large for an input sequence of length n2 + 1.
  • Note that in our example n2 + 1 = 32 + 1 = 10 that is, we are interested

in 4 length subsequences.

  • Is there a 4 length increasing subsequence? Yes! 5, 8, 12, 15.
  • Is there a 4 length deceasing subsequence? Yes! 5, 3, 2, 1.
  • Finally, note the or. That is, we are content with either a large increasing

subsequence or a large decreasing subsequence.

  • Note that if you have a monotonically increasing sequence as your input,

you cannot find even a 2 length decreasing subsequence (forget large!).

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-44
SLIDE 44

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-45
SLIDE 45

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-46
SLIDE 46

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence.

Attempt a proof. If not pigeon hole principle, any other method.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-47
SLIDE 47

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence.

Attempt a proof. If not pigeon hole principle, any other method.

Do try a proof on your own else you will not appreciate the clever idea.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-48
SLIDE 48

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence.

Attempt a proof. If not pigeon hole principle, any other method.

Do try a proof on your own else you will not appreciate the clever idea. Note that if a desired (inc.) subsequence exists, it must start at some as and has length say is ≥ n + 1. How about asking what is the longest inc. subsequence starting at every element?

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-49
SLIDE 49

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence.

Attempt a proof. If not pigeon hole principle, any other method.

Do try a proof on your own else you will not appreciate the clever idea. Note that if a desired (inc.) subsequence exists, it must start at some as and has length say is ≥ n + 1. How about asking what is the longest inc. subsequence starting at every element? We will associate two integers ik and dk with an element ak in the sequence.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-50
SLIDE 50

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence.

Attempt a proof. If not pigeon hole principle, any other method.

Do try a proof on your own else you will not appreciate the clever idea. Note that if a desired (inc.) subsequence exists, it must start at some as and has length say is ≥ n + 1. How about asking what is the longest inc. subsequence starting at every element? We will associate two integers ik and dk with an element ak in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-51
SLIDE 51

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence.

Attempt a proof. If not pigeon hole principle, any other method.

Do try a proof on your own else you will not appreciate the clever idea. Note that if a desired (inc.) subsequence exists, it must start at some as and has length say is ≥ n + 1. How about asking what is the longest inc. subsequence starting at every element? We will associate two integers ik and dk with an element ak in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

Side Question: How do we compute ik and dk algorithmically? It is not needed for this proof, but interesting on its own.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-52
SLIDE 52

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 We will associate two integers ik and dk with an element ak in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-53
SLIDE 53

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 We will associate two integers ik and dk with an element ak in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

Lets write some ik, dk values for the example above.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-54
SLIDE 54

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 We will associate two integers ik and dk with an element ak in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

Lets write some ik, dk values for the example above.

  • i1 = 5 since we have a 5 length increasing subsequence starting at a1 = 5.

The subsequence is 5, 7, 8, 12, 15.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-55
SLIDE 55

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 We will associate two integers ik and dk with an element ak in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

Lets write some ik, dk values for the example above.

  • i1 = 5 since we have a 5 length increasing subsequence starting at a1 = 5.

The subsequence is 5, 7, 8, 12, 15. Further there is no 6 length increasing subsequence starting at a1.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-56
SLIDE 56

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 We will associate two integers ik and dk with an element ak in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

Lets write some ik, dk values for the example above.

  • i1 = 5 since we have a 5 length increasing subsequence starting at a1 = 5.

The subsequence is 5, 7, 8, 12, 15. Further there is no 6 length increasing subsequence starting at a1.

  • d1 = 4 since we have a 4 length decreasing subsequence starting at a1 = 5.

The subsequence is 5, 3, 2, 1.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-57
SLIDE 57

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 We will associate two integers ik and dk with an element ak in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

Lets write some ik, dk values for the example above.

  • i1 = 5 since we have a 5 length increasing subsequence starting at a1 = 5.

The subsequence is 5, 7, 8, 12, 15. Further there is no 6 length increasing subsequence starting at a1.

  • d1 = 4 since we have a 4 length decreasing subsequence starting at a1 = 5.

The subsequence is 5, 3, 2, 1. Further there is no 5 length decreasing subsequence starting at a1.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-58
SLIDE 58

Example 3: Increasing / decreasing subsequences

We are given a sequence of n2 + 1 distinct integers say as below. 5, 7, 3, 2, 1, 8, 12, 15, 13, 6 We will associate two integers ik and dk with an element ak in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

Lets write some ik, dk values for the example above.

  • i1 = 5 since we have a 5 length increasing subsequence starting at a1 = 5.

The subsequence is 5, 7, 8, 12, 15. Further there is no 6 length increasing subsequence starting at a1.

  • d1 = 4 since we have a 4 length decreasing subsequence starting at a1 = 5.

The subsequence is 5, 3, 2, 1. Further there is no 5 length decreasing subsequence starting at a1.

  • Write down i2, d2.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-59
SLIDE 59

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing

  • subsequence. We will associate two integers with every element in the
  • sequence. Those are ik and dk.
  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-60
SLIDE 60

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing

  • subsequence. We will associate two integers with every element in the
  • sequence. Those are ik and dk.
  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

If our claim is false, each of ik and dk is at most n

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-61
SLIDE 61

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing

  • subsequence. We will associate two integers with every element in the
  • sequence. Those are ik and dk.
  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

If our claim is false, each of ik and dk is at most n (because if any one was n + 1 we are done).

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-62
SLIDE 62

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing

  • subsequence. We will associate two integers with every element in the
  • sequence. Those are ik and dk.
  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

If our claim is false, each of ik and dk is at most n (because if any one was n + 1 we are done). The smallest value that ik and dk can take is 1. Thus we have pairs (ik, dk) and possible values for each of them is 1, . . . n.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-63
SLIDE 63

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing

  • subsequence. We will associate two integers with every element in the
  • sequence. Those are ik and dk.
  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

If our claim is false, each of ik and dk is at most n (because if any one was n + 1 we are done). The smallest value that ik and dk can take is 1. Thus we have pairs (ik, dk) and possible values for each of them is 1, . . . n. Thus we can form at most n2 pairs.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-64
SLIDE 64

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing

  • subsequence. We will associate two integers with every element in the
  • sequence. Those are ik and dk.
  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

If our claim is false, each of ik and dk is at most n (because if any one was n + 1 we are done). The smallest value that ik and dk can take is 1. Thus we have pairs (ik, dk) and possible values for each of them is 1, . . . n. Thus we can form at most n2 pairs. Here is where we use pigeon hole principle.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-65
SLIDE 65

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing

  • subsequence. We will associate two integers with every element in the
  • sequence. Those are ik and dk.
  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

If our claim is false, each of ik and dk is at most n (because if any one was n + 1 we are done). The smallest value that ik and dk can take is 1. Thus we have pairs (ik, dk) and possible values for each of them is 1, . . . n. Thus we can form at most n2 pairs. Here is where we use pigeon hole principle. However, we have n2 + 1 elements in the input sequence. Thus there must be two elements as and at such that is = it and ds = dt. Further note that we can assume as appears before at in the sequence. That is, s < t.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-66
SLIDE 66

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence. We will associate two integers ik and dk with every element in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

We have established that there must be two elements as and at such that is = it and ds = dt. Further note that we can assume as appears before at in the sequence. That is, s < t.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-67
SLIDE 67

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence. We will associate two integers ik and dk with every element in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

We have established that there must be two elements as and at such that is = it and ds = dt. Further note that we can assume as appears before at in the sequence. That is, s < t. Now, recall elements are distinct hence either as < at or as > at.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-68
SLIDE 68

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence. We will associate two integers ik and dk with every element in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

We have established that there must be two elements as and at such that is = it and ds = dt. Further note that we can assume as appears before at in the sequence. That is, s < t. Now, recall elements are distinct hence either as < at or as > at.

  • If as < at, then we can take the increasing sequence starting at at and

append as to that to improve is = it + 1.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-69
SLIDE 69

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence. We will associate two integers ik and dk with every element in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

We have established that there must be two elements as and at such that is = it and ds = dt. Further note that we can assume as appears before at in the sequence. That is, s < t. Now, recall elements are distinct hence either as < at or as > at.

  • If as < at, then we can take the increasing sequence starting at at and

append as to that to improve is = it + 1.

  • On the other hand, if as > at we can improve the length of the decreasing

sequence at as by prepending as to the dt length decreasing sequence.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-70
SLIDE 70

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence. We will associate two integers ik and dk with every element in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

We have established that there must be two elements as and at such that is = it and ds = dt. Further note that we can assume as appears before at in the sequence. That is, s < t. Now, recall elements are distinct hence either as < at or as > at.

  • If as < at, then we can take the increasing sequence starting at at and

append as to that to improve is = it + 1.

  • On the other hand, if as > at we can improve the length of the decreasing

sequence at as by prepending as to the dt length decreasing sequence. Thus, we cannot have a pair as and at with is = it and ds = dt.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-71
SLIDE 71

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence. We will associate two integers ik and dk with every element in the sequence.

  • ik denotes the longest increasing subsequence starting at ak.
  • dk denotes the longest decreasing subsequence starting at ak.

We have established that there must be two elements as and at such that is = it and ds = dt. Further note that we can assume as appears before at in the sequence. That is, s < t. Now, recall elements are distinct hence either as < at or as > at.

  • If as < at, then we can take the increasing sequence starting at at and

append as to that to improve is = it + 1.

  • On the other hand, if as > at we can improve the length of the decreasing

sequence at as by prepending as to the dt length decreasing sequence. Thus, we cannot have a pair as and at with is = it and ds = dt. Note that this was true because all of ik and dk were at most n. However, there must be at least one which is ≥ n + 1.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-72
SLIDE 72

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence. Remarks

  • This is a non-trivial proof using pigeon hole principle.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-73
SLIDE 73

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence. Remarks

  • This is a non-trivial proof using pigeon hole principle.
  • Revisit the proof and make sure you understand it completely.

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-74
SLIDE 74

Example 3: Increasing / decreasing subsequences

Theorem: Given any n2 + 1 length sequence of distinct integers there is either an n + 1 strictly increasing subsequence or an n + 1 strictly decreasing subsequence. Remarks

  • This is a non-trivial proof using pigeon hole principle.
  • Revisit the proof and make sure you understand it completely.
  • Read Examples 11, 12, 13 of 6.2 [KR]

CS1200, CSE IIT Madras Meghana Nasre Counting

slide-75
SLIDE 75

Summary

  • Pigeonhole principle and its generalization.
  • Simple and interesting applications.
  • A non-trivial and elegant application to increasing / decreasing

subsequences.

  • Reference: Section 6.2 [KR].

CS1200, CSE IIT Madras Meghana Nasre Counting