Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.

Slides:



Advertisements
Similar presentations
Practice Quiz 3 Recursive Definitions Relations Basic Counting Pigeonhole Principle Permutations & Combinations Discrete Probability.
Advertisements

Counting Chapter 6 With Question/Answer Animations.
1 Section 4.3 Permutations & Combinations. 2 Permutation Set of distinct objects in an ordered arrangement An ordered arrangement of r members of a set.
Permutations and Combinations Rosen 4.3. Permutations A permutation of a set of distinct objects is an ordered arrangement these objects. An ordered arrangement.
Counting Chapter 6 With Question/Answer Animations.
Recursively Defined Functions
THE BASIC OF COUNTING Discrete mathematics KNURE, Software department, Ph , N.V. Bilous.
CSE115/ENGR160 Discrete Mathematics 04/17/12
Recursive Definitions Rosen, 3.4. Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
Permutations r-permutation (AKA “ordered r-selection”) An ordered arrangement of r elements of a set of n distinct elements. permutation of a set of n.
Lecture 5 Counting 4.3, Permutations r-permutation: An ordered arrangement of r elements of a set of n distinct elements. Example: S={1,2,3}:
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
Climbing an Infinite Ladder
Permutations and Combinations
CS100 : Discrete Structures
4. Counting 4.1 The Basic of Counting Basic Counting Principles Example 1 suppose that either a member of the faculty or a student in the department is.
Combinatorics 3/15 and 3/ Counting A restaurant offers the following menu: Main CourseVegetablesBeverage BeefPotatoesMilk HamGreen BeansCoffee.
Discrete Mathematics CS 2610 March 26, 2009 Skip: structural induction generalized induction Skip section 4.5.
Counting Chapter 6 With Question/Answer Animations.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
Induction and recursion
Jessie Zhao Course page: 1.
Counting. Why counting  Determine the complexity of algorithms To sort n numbers, how many instructions are executed ?  Count the number of objects.
The Basics of Counting Section 6.1.
Counting. Product Rule Example Sum Rule Pigeonhole principle If there are more pigeons than pigeonholes, then there must be at least one pigeonhole.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Chapter 6 With Question/Answer Animations 1. Chapter Summary The Basics of Counting The Pigeonhole Principle Permutations and Combinations Binomial Coefficients.
Permutations and Combinations
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
ICS 253: Discrete Structures I Counting and Applications King Fahd University of Petroleum & Minerals Information & Computer Science Department.
Lecture 5 Counting 4.3, Permutations r-permutation: An ordered arrangement of r elements of a set of n distinct elements. Example: S={1,2,3}:
4.1.2 Pigeonhole principle:Strong Form  Theorem 4.2: Let q 1,q 2,…,q n be positive integers. If q 1 +q 2 +…+q n -n+1 objects are put into n boxes, then.
The Basics of Counting Section 6.1.
Module #15: Combinatorics Rosen 5 th ed., §§ & §6.5 Now we are moving on to Ch. 4 It is the study of arrangement of objects e.g. enumeration, counting.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Discrete Structures1 One, two, three, we’re… Counting.
The Pigeonhole Principle. The pigeonhole principle Suppose a flock of pigeons fly into a set of pigeonholes to roost If there are more pigeons than pigeonholes,
CS 103 Discrete Structures Lecture 16
Mathematical Induction Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
2/24/20161 One, two, three, we’re… Counting. 2/24/20162 Basic Counting Principles Counting problems are of the following kind: “How many different 8-letter.
Introduction Suppose that a password on a computer system consists of 6, 7, or 8 characters. Each of these characters must be a digit or a letter of the.
Section Basic Counting Principles: The Product Rule The Product Rule: A procedure can be broken down into a sequence of two tasks. There are n 1.
CS 104: Discrete Mathematics
Discrete Mathematics. Exercises Exercise 1:  There are 18 Computer Science (CS) majors and 325 Business Administration (BA) majors at a college.
Section The Pigeonhole Principle If a flock of 20 pigeons roosts in a set of 19 pigeonholes, one of the pigeonholes must have more than 1 pigeon.
Chapter 6 With Question/Answer Animations Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written.
ICS 253: Discrete Structures I Counting and Applications King Fahd University of Petroleum & Minerals Information & Computer Science Department.
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 5 Counting 歐亞書局.
Section The Product Rule  Example: How many different license plates can be made if each plate contains a sequence of three uppercase English letters.
COUNTING Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
Section 6.3. Section Summary Permutations Combinations.
Example A standard deck of 52 cards has 13 kinds of cards, with four cards of each of kind, one in each of the four suits, hearts, diamonds, spades, and.
The Pigeonhole Principle
CSE15 Discrete Mathematics 04/19/17
ICS 253: Discrete Structures I
The Pigeonhole Principle
Discrete Structures for Computer Science
COCS DISCRETE STRUCTURES
Permutations and Combinations
Induction and Recursion
Counting Chapter 6 With Question/Answer Animations
Recursively Defined Functions
CS100: Discrete structures
Module #15: Combinatorics
Permutations and Combinations
Module #15: Combinatorics
Presentation transcript:

Recursive Definitions Rosen, 3.4

Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called recursion. –Sequences {s 0,s 1,s 2, …} defined by s 0 = a and s n = 2s n-1 + b for constants a and b and n  Z+ –Sets 3  S and x+y  S if x  S and y  S –Functions Example: f(n) = 2 n, f(n) = 2f(n-1) and f(0) = 1

Recursively Defined Functions To define a function with the set of nonnegative integers as its domain 1.Specify the value of the function at zero (or sometimes, it first k terms). 2.Give a rule for finding its value at an integer from its values at smaller integers.

Examples of Recursively Defined Functions Factorial Function n!  n! = n(n-1)(n-2)….(1)  f(0) = 1, f(n) = n(f(n-1)) a n  f(0) = 1, f(n+1) = f(n)*a Fibonacci Numbers  f 0 =0, f 1 =1, f n+1 = f n + f n-1  {0,1,1,2,3,5,8,13,...}

Prove that the nth term in the Fibonacci sequence iswhen n  2 Induction Proof: Basic Step: Let n = 2, then f 2 = 1 = =1+0 Inductive Step: Consider k  2 and assume that the expression is true for 2  n  k. We must show that the expression is true for n = k+1, i.e., that f k+1 f k+1 = f k +f k-1 by definition by the inductive hypothesis

Fibonacci Proof (cont.) Since f 2 is true and [f n is true for 2  n  k  f k+1 ] is true, then f n is true for all positive integers n  2.

Find a closed form solution to T(1) = c 0, T(n) = 2T(n-1)+c 1 T(1) = c 0 T(2) = 2T(1) + c 1 = 2c 0 + c 1 T(3) = 2T(2)+c 1 = 2(2c 0 +c 1 )+c 1 = 4c 0 +3c 1 T(4) = 2T(3)+c 1 = 2(4c 0 +3c 1 )+c 1 = 8c 0 +7c 1 T(5) = 2T(4)+c 1 = 2(8c 0 +7c 1 )+c 1 = 16c 0 +15c 1 Guess that T(n) = 2 n-1 c 0 + (2 n-1 -1)c 1

Prove that T(1) = c 0, T(n) = 2T(n-1)+c 1 has closed form solution T(n) = 2 n-1 c 0 + (2 n-1 -1)c 1 Basis Step: T(1) = c 0 + ( )c 1 = c 0 Induction Step: Assume that T(n) = 2 n-1 c 0 + (2 n-1 -1)c 1. We must show that T(n+1) = 2 (n+1)-1 c 0 + (2 (n+1)-1 -1)c 1 = 2 n c 0 + (2 n -1)c 1. T(n+1) = 2T(n) + c 1 = 2[2 n-1 c 0 + (2 n-1 -1)c 1 ]+ c 1 = 2 n c 0 + (2 n -2)c 1 + c 1 = 2 n c n c 1 - c 1 = 2 n c 0 + (2 n -1)c 1.

Using Matrices For finite sets we can use zero-one matrices. Elements of each set A and B must be listed in some particular (but arbitrary) order. When A=B we use the same ordering for A and B. m ij = 1 if (a i,b j )  R = 0 if (a i,b j )  R

Example Zero-One Matrix b1b2b3 a1 a2 a3 R = {(a1,b1), (a1,b2), (a2,b2), (a3,b2), (a3,b3)}

Basic Counting Rosen 4.1

Sum Rule If a first task can be done in n 1 ways and a second task can be done in n 2 ways, and if these tasks cannot be done at the same time (i.e., the tasks are either/or), then there are n 1 + n 2 ways to do either task. If A and B are disjoint sets then |A  B|  |A|  |B| In general if A 1, A 2...A n are disjoint sets, then |A 1  A 2 ...  A n | = |A 1 | + |A 2 | |A n |

Product Rule Suppose that a procedure can be broken down into two tasks. If there are n 1 ways to do the first task and n 2 ways to do the second task after the first task has been done, then there are n 1 n 2 ways to do the procedure. If A and B are disjoint sets then | A  B | = | A | | B| In general if A 1, A 2...A n are disjoint sets, then |A 1  A 2 ...  A n | = |A 1 | |A 2 |... |A n |

Examples There are 18 math majors and 325 computer science majors at a college –How many ways are there to pick two representatives, so that one is a math major and the other is a computer science major? 18*325 = 5850 –How many ways are there to pick one representative who is either a math major or a computer science major? = 343

Examples A multiple choice test contains 10 questions. There are four possible answers for each question. –How many ways can a student answer the questions on the test if every question is answered? 4*4*4*4*4*4*4*4*4*4 = 4 10 –How many ways can a student answer the questions on the test if the student can leave answers blank? 5*5*5*5*5*5*5*5*5*5 = 5 10

Principle of Inclusion-Exclusion When two tasks can be done at the same time we add the number of ways to do each of the two tasks, then subtract the number of ways to do both tasks. If A and B are not disjoint |A  B|  |A|  |B|  |A  B| –Don't count objects in the intersection of two sets more than once!

How many bit strings of length eight either start with 1 or end with the two bits 00? Add (number of bit strings that look like 1xxxxxxx) to the (number of bit strings that look like xxxxxx00) minus the (number of bit string that look like 1xxxxx00) 1*2*2 *2 *2 *2 *2 *2 + 2* 2* 2* 2* 2* 2*1*1 – 1*2*2*2*2*2*1*1 = = 2 5 (4+2-1) = 5*2 5 = 5*32 = 160

The Pigeonhole Principle Rosen 4.2

Pigeonhole Principle If k+1 or more objects are placed into k boxes, then there is at least one box containing two or more objects.

Generalized Pigeonhole Principle If N objects are placed into k boxes, then there is at least one box containing at least  N/k  objects Examples –Among any 100 people there must be at least  100/12  = 9 who were born in the same month. –What is the minimum number of students needed in a class to be sure that at least 6 to get the same grade? (5 choices for grades:A,B,C,D,F) Smallest integer N such that  N/5  = 6, 5*5+1 = 26

Example What’s the minimum number of students, each of whom comes from one of the 50 states must be enrolled in a university to guarantee that there are at least 100 who come from the same state? 50* = 4951  4951/50  = 100

Permutations and Combinations Rosen 4.3

Permutations A permutation of a set of distinct objects is an ordered arrangement these objects. An ordered arrangement of r elements of a set is called an r-permutation. The number of r-permutations of a set with n elements is denoted by P(n,r). A = {1,2,3,4} 2-permutations of A include 1,2; 2,1; 1,3; 2,3; etc…

Counting Permutations Using the product rule we can find P(n,r) = n*(n-1)*(n-2)* …*(n-r+1) = n!/(n-r)! How many 2-permutations are there for the set {1,2,3,4}? P(4,2)

Combinations An r-combination of elements of a set is an unordered selection of r element from the set. (i.e., an r-combination is simply a subset of the set with r elements). Let A={1,2,3,4} 3-combinations of A are {1,2,3}, {1,2,4}, {1,3,4}, {2,3,4}(same as {3,2,4}) The number of r-combinations of a set with n distinct elements is denoted by C(n,r).

Example Let A = {1,2,3} 2-permutations of A are: 1,2 2,1 1,3 3,1 2,3 3,2 6 total.Order is important 2-combinations of A are: {1,2}, {1,3}, {2,3} 3 total. Order is not important If we counted the number of permutations of each 2-combination we could figure out P(3,2)!

How to compute C(n,r) To find P(n,r), we could first find C(n,r), then order each subset of r elements to count the number of different orderings. P(n,r) = C(n,r)P(r,r). So C(n,r) = P(n,r) / P(r,r)

The English alphabet contains 21 consonants and 5 vowels. How many strings of six lower case letters of the English alphabet contain: exactly 2 vowels? Choose position for the vowels. C(6,2) = 6!/2!4! = 15 Choose the two vowels. 5 choices for each of 2 positions = 5 2 Each of the other 4 positions can contain any of 21 consonants *5 2 *21 4

The English alphabet contains 21 consonants and 5 vowels. How many strings of six lower case letters of the English alphabet contain: at least 1 vowel Count the number of strings with no vowels and subtract this from the total number of strings

Binomial Coefficient Another notation for C(n,r) is. This number is also called a binomial coefficient. These numbers occur as coefficients in the expansions of powers of binomial expressions such as (a+b) n.

Binomial Theorem Let x and y be variables and let n be a positive integer. Then