Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.

Similar presentations


Presentation on theme: "ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department."— Presentation transcript:

1 ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department

2 Induction and Recursion ICS 253: Discrete Structures I Reading Assignment K. H. Rosen, Discrete Mathematics and Its Applications, 6 th Ed., McGraw-Hill, 2006.Discrete Mathematics and Its Applications Chapter 4 Sections 4.1, 4.2 and 4.3 2

3 Induction and Recursion ICS 253: Discrete Structures I Introduction Many mathematical statements assert that a property is true for all positive integers. e.g. n!  n n Many functions are defined based on certain “rules” i.e. recursively. 3

4 Induction and Recursion ICS 253: Discrete Structures I Section 4.1: Mathematical Induction 4

5 Induction and Recursion ICS 253: Discrete Structures I Mathematical Induction Mathematical induction is an extremely important proof technique that is used extensively to prove results about a large variety of discrete objects. Complexity of algorithms Correctness of certain types of computer programs Theorems about graphs and trees, A wide range of identities and inequalities…etc. 5

6 Induction and Recursion ICS 253: Discrete Structures I Mathematical Induction Mathematical induction is used to prove propositions of the form:  n P(n), where the universe of discourse is the set of positive integers 6

7 Induction and Recursion ICS 253: Discrete Structures I First Form of Mathematical Induction Basis Step: P(1) is shown to be true Inductive Step: The implication P(n)  P(n+1) is shown to be true for every positive integer n Question: Is this the same as circular reasoning??? As a rule of inference: [P(1)   n (P(n)  P(n+1))]   n P(n) Inductive Hypothesis 7

8 Induction and Recursion ICS 253: Discrete Structures I Examples Prove that Proof: 8

9 Induction and Recursion ICS 253: Discrete Structures I Examples Prove that the sum of the first n odd positive integers is n 2 9

10 Induction and Recursion ICS 253: Discrete Structures I Examples Prove that n < 2 n  n 10

11 Induction and Recursion ICS 253: Discrete Structures I Examples Prove that 2 n < n! for n  4 11

12 Induction and Recursion ICS 253: Discrete Structures I Examples Prove that n 3 – n is divisible by 3  n  Z + 12

13 Induction and Recursion ICS 253: Discrete Structures I Examples Use mathematical induction to show that n=0,1,2,… where 13

14 Induction and Recursion ICS 253: Discrete Structures I Examples Use mathematical induction to show that if S is a finite set with n elements where n is a nonnegative integer, then S has 2 n subsets. 14

15 Induction and Recursion ICS 253: Discrete Structures I Examples Use mathematical induction to prove the following generalization of one of De Morgan's laws: whenever A 1, A 2,..., A n are subsets of a universal set U and n  2. 15

16 Induction and Recursion ICS 253: Discrete Structures I Examples Let n be a +ve integer. Show that any 2 n  2 n chessboard with one square removed can be tiled using L-shaped pieces, where these pieces cover three squares at a time as shown below 16

17 Induction and Recursion ICS 253: Discrete Structures I Sketch of The Solution Basis Step: Induction Step: Inductive Hypothesis Subsquare having the real hole Subsquare with ‘artificial’ hole at lower right corner Subsquare with ‘artificial’ hole at lower left corner Subsquare with ‘artificial’ hole at upper left corner 17

18 Induction and Recursion ICS 253: Discrete Structures I Section 4.2: Strong Induction and Well Ordering Strong induction is similar to the mathematical induction in both requiring a basis step. Strong induction differs in the inductive step, where we assume that the statement P(j) is true for all j  k, and then prove that P holds for j=k+1. The validity of both mathematical induction and strong induction follow from the well-ordering property. In fact, mathematical induction, strong induction, and well-ordering are all equivalent principles. 18

19 Induction and Recursion ICS 253: Discrete Structures I Strong Induction Basis Step: P(1) is shown to be true Inductive Step: [P(1)  P(2)  …  P(n)]  P(n+1) is shown to be true for every positive integer n 19

20 Induction and Recursion ICS 253: Discrete Structures I Examples Suppose we can reach the first and second rungs of an infinite ladder, and we know that if we can reach a rung, then we can reach two rungs higher. Can we prove that we can reach every rung using the principle of mathematical induction? Can we prove that we can reach every rung using strong induction? 20

21 Induction and Recursion ICS 253: Discrete Structures I Examples Show that if n is an integer greater than 1, then n can be written as the product of primes. 21

22 Induction and Recursion ICS 253: Discrete Structures I Examples Prove that every amount of postage of 12 cents or more can be formed using just 4-cent and 5-cent stamps. 22

23 Induction and Recursion ICS 253: Discrete Structures I Well Ordering Property Mathematical induction follows from the following fundamental axiom The Well Ordering Property: Every non- empty set of nonnegative integers has a least element The well ordering property can often be used directly in proofs. 23

24 Induction and Recursion ICS 253: Discrete Structures I Section 4.3: Recursive Definitions and Structural Induction 24 Sometimes it is difficult to define an object explicitly. However, it may be easy to define this object in terms of itself. This process is called recursion.

25 Induction and Recursion ICS 253: Discrete Structures I Recursive Definitions and Structural Induction Recursion can be used to define sequences, functions and sets Sequences: can also be defined as Functions: Similar to sequences After all, sequences are, themselves, functions! Sets 25

26 Induction and Recursion ICS 253: Discrete Structures I Recursively Defined Functions Q3 pp 308: Find f(2), f(3), f(4), and f(5) if f is defined recursively by f(0) = –1, f(l) = 2 and for n = 1,2,... a) f(n + 1) = f(n) + 3f(n – 1). b) f(n + 1) = f(n) 2 f(n – 1). c) f(n + 1) = 3f(n) 2 – 4f(n – 1) 2. d) f(n + 1) = f(n – l)/f(n). 26

27 Induction and Recursion ICS 253: Discrete Structures I Recursively Defined Functions Give an inductive definition of the factorial function F(n) = n!. Give a recursive definition of 27

28 Induction and Recursion ICS 253: Discrete Structures I Fibonacci Numbers Definition: The Fibonacci numbers, f 0, f 1, f 2,..., are defined by the equations f 0 = 0, f 1 = 1, and f n = f n – l + f n – 2 for n = 2, 3, 4,.... Show that whenever n  3, f n >  n – 2, where 28

29 Induction and Recursion ICS 253: Discrete Structures I Recursively Defined Sets and Structures In recursively defined sets, the basis step defines some initial elements and the recursive step defines a rule for constructing new elements from those already in the set. Recursive definitions may also include an exclusion rule, which specifies that a recursively defined set contains nothing other than those elements specified in the basis step or generated by applications of the recursive step. We will assume that it always holds. To prove results about recursively defined sets we use a method called structural induction. 29

30 Induction and Recursion ICS 253: Discrete Structures I Example Consider the subset S of the set of integers defined by Basis step: 3  S. Recursive step: If x  S and y  S, then x + y  S. Show that S is the set of all positive integers that are multiples of 3. 30

31 Induction and Recursion ICS 253: Discrete Structures I Strings Over Alphabet  Definition: The set  * of strings over the alphabet  can be defined recursively by Basis step:  * (where is the empty string containing no symbols). Recursive step: If w  * and x , then wx  *. Example: What are the strings formed over  ={0,1}? 31

32 Induction and Recursion ICS 253: Discrete Structures I Concatenation of Strings Definition: Two strings can be combined via the operation of concatenation. Let  be a set of symbols and  * the set of strings formed from symbols in . We can define the concatenation of two strings, denoted by., recursively as follows. Basis step: If w   *, then w · = w, where is the empty string. Recursive step: If w 1  * and w 2  * and x , then w 1 · (w 2 x ) = (w 1. w 2 )x. Usually, w 1. w 2 is denoted by w 1 w 2 32

33 Induction and Recursion ICS 253: Discrete Structures I Length of a String Give a recursive definition of l(w), the length of the string w. Solution: The length of a string can be defined by l( ) = 0; l(wx) = l(w) + 1 if w   * and x  . Use structural induction to prove that l(xy) = I(x) + l(y). 33

34 Induction and Recursion ICS 253: Discrete Structures I Well-Formed Formulae Well-Formed Formulae for Compound Statement Forms We can define the set of well-formed formulae for compound statement forms involving T, F, propositional variables, and operators from the set { , , , ,  } as follows Basis step: T, F, and s, where s is a propositional variable, are well- formed formulae. Recursive step: If E and F are well-formed formulae, then (  E), (E  F), (E  F), (E  F), and (E  F) are well-formed formulae. Is (p  q)  (q  F) a well-formed formula? Is p   q a well-formed formula? Can you similarly define well-formed formulae for operators and operands? Show that every well-formed formulae for compound propositions contains an equal number of left and right parentheses. 34

35 Induction and Recursion ICS 253: Discrete Structures I Rooted Trees Definition: The set of rooted trees, where a rooted tree consists of a set of vertices containing a distinguished vertex called the root, and edges connecting these vertices, can be defined recursively by these steps: Basis step: A single vertex r is a rooted tree. Recursive step: Suppose that T 1, T 2,..., T n are disjoint rooted trees with roots r l, r 2,..., r n, respectively. Then the graph formed by starting with a root r, which is not in any of the rooted trees T 1, T 2,..., T n, and adding an edge from r to each of the vertices r 1, r 2,..., r n, is also a rooted tree.. 35

36 Induction and Recursion ICS 253: Discrete Structures I Building Up Rooted Trees 36

37 Induction and Recursion ICS 253: Discrete Structures I Extended Binary Trees Definition: The set of extended binary trees can be defined recursively by these steps: Basis step: The empty set is an extended binary tree. Recursive step: If T 1 and T 2 are disjoint extended binary trees, there is an extended binary tree, denoted by T l · T 2, consisting of a root r together with edges connecting the root to each of the roots of the left subtree T l and the right subtree T 2 when these trees are nonempty. 37

38 Induction and Recursion ICS 253: Discrete Structures I Building Extended Binary Trees 38

39 Induction and Recursion ICS 253: Discrete Structures I Full Binary Trees Definition: The set of full binary trees can be defined recursively by these steps: Basis step: There is a full binary tree consisting only of a single vertex r. Recursive step: If T l and T 2 are disjoint full binary trees, there is a full binary tree, denoted by T l · T 2, consisting of a root r together with edges connecting the root to each of the roots of the left subtree T l and the right subtree T 2. 39

40 Induction and Recursion ICS 253: Discrete Structures I Examples of Full Binary Trees 40

41 Induction and Recursion ICS 253: Discrete Structures I Full Binary Trees Denote the number of nodes in full binary tree T as n(T). Can you provide a recursive definition of n(T)? Definition: The height h(T) of a full binary tree T recursively as follows Basis step: The height of the full binary tree T consisting of only a root r is h(T) = 0. Recursive step: If T 1 and T 2 are full binary trees, then the full binary tree T = T 1 · T 2 has height h(T) = 1 + max(h(T 1 ), h(T 2 )) 41

42 Induction and Recursion ICS 253: Discrete Structures I Full Binary Trees Theorem: If T is a full binary tree, then Proof (By Structural Induction): 42

43 Induction and Recursion ICS 253: Discrete Structures I Full Binary Trees Definition: A leaf node is a node that has no children. Definition: An internal node is a node that has one or more children. Prove that in any full binary tree, the number of leaf nodes is one more than the number of internal nodes. 43

44 Induction and Recursion ICS 253: Discrete Structures I Generalized Induction Instead of using induction on Z + or N, we can extend it to any set having the well-ordering property For example, consider N  N with the following property (called lexicographic ordering) (x 1, y 1 ) is less than or equal to (x 2, y 2 ) if either x 1 <x 2, or x 1 =x 2 and y 1 <y 2 ; 44

45 Induction and Recursion ICS 253: Discrete Structures I Example Suppose that a m,n is defined recursively for (m, n)  N  N Show that a m,n = m + n(n + 1)/2 for all (m,n)  N  N 45


Download ppt "ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department."

Similar presentations


Ads by Google