CS2210:0001Discrete Structures Induction and Recursion

Slides:



Advertisements
Similar presentations
22C:19 Discrete Structures Induction and Recursion Spring 2014 Sukumar Ghosh.
Advertisements

22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
Recursive Definitions and Structural Induction
Induction and Recursion. Odd Powers Are Odd Fact: If m is odd and n is odd, then nm is odd. Proposition: for an odd number m, m k is odd for all non-negative.
UCI ICS/Math 6A, Summer Recursion -1 after Strong Induction “Normal” Induction “Normal” Induction: If we prove.
Induction and recursion
CSE115/ENGR160 Discrete Mathematics 04/03/12 Ming-Hsuan Yang UC Merced 1.
CSE 321 Discrete Structures Winter 2008 Lecture 12 Induction.
CSE115/ENGR160 Discrete Mathematics 03/31/11
Chapter Mathematical Induction
Section Section Summary Recursive Algorithms Proving Recursive Algorithms Correct Recursion and Iteration (not yet included in overheads) Merge.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen Induction.
Climbing an Infinite Ladder
Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.
Induction and recursion
22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.
Induction and recursion
Recursive Definitions and Structural Induction
Induction and recursion
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 4 Induction and Recursion 歐亞書局.
Chapter 4: Induction and Recursion
CSE 311 Foundations of Computing I Lecture 16 Recursively Defined Sets and Structural Induction Spring
Section 5.3. Section Summary Recursively Defined Functions Recursively Defined Sets and Structures Structural Induction.
INDUCTION AND RECURSION. PRINCIPLE OF MATHEMATICAL INDUCTION To prove that P(n) is true for all positive integers n, where P(n) is a propositional function,
Induction and recursion
Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.
Chapter 5 With Question/Answer Animations. Section 5.1.
4.3 Recursive Definitions and Structural Induction Sometimes it is difficult to define an object explicitly. However, it may be easy to define this object.
Induction Proof. Well-ordering A set S is well ordered if every subset has a least element. [0, 1] is not well ordered since (0,1] has no least element.
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
CompSci 102 Discrete Math for Computer Science March 1, 2012 Prof. Rodger Slides modified from Rosen.
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
1 Recursive Definitions and Structural Induction CS 202 Epp section ??? Aaron Bloomfield.
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.
Mathematical Induction
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
Chapter 5. 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 we can reach.
Chapter 5 Kenneth Rosen, Discrete Mathematics and its Applications, 7th edition, McGraw Hill Instructor: Longin Jan Latecki, Copyright.
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
Induction and Recursion CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
1 Recursive Definitions and Structural Induction CS/APMA 202 Rosen section 3.4 Aaron Bloomfield.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Mathematical Induction And Recursion Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
Fall 2002CMSC Discrete Structures1 Chapter 3 Sequences Mathematical Induction Recursion Recursion.
Chapter 5 1. Chapter Summary  Mathematical Induction  Strong Induction  Recursive Definitions  Structural Induction  Recursive Algorithms.
Hubert Chan (Chapters 1.6, 1.7, 4.1)
Chapter 4: Induction and Recursion
Induction and recursion
Recursive Algorithms Section 5.4.
CSE15 Discrete Mathematics 04/12/17
Induction and Recursion Chapter 5
Induction and recursion
Induction and Recursion
CSE 311: Foundations of Computing
Hubert Chan (Chapters 1.6, 1.7, 4.1)
Mathematical Induction Recursion
Discrete Structures for Computer Science
Chapter 5 Induction and Recursion
Induction and recursion
CSI Mathematical Induction
Applied Discrete Mathematics Week 9: Integer Properties
Chapter 4 Induction and Recursion
Induction Chapter
Mathematical Induction
Math/CSE 1019: Discrete Mathematics for Computer Science Fall 2011
Induction and recursion
Induction and recursion
Recursion.
Presentation transcript:

CS2210:0001Discrete Structures Induction and Recursion Fall 2017 Sukumar Ghosh

What is mathematical induction? It is a method of proving that something holds. Suppose we have an infinite ladder, and we want to know if we can reach every step on this ladder. We know the following two things: We can reach the base of the ladder If we can reach a particular step, then we can reach the next step Can we conclude that we can reach every step of the ladder? YES!

Understanding induction Suppose we want to prove that P(x) holds for all x

Proof structure

Example 1

Example continued

Example continued

What did we show?

Example 2

Example continued

Example continued

Example 3

Exercise Prove by induction the following: 1. 2.

A Tiling Problem Prove by induction that you can tile any (2n x 2n) checkerboard (n>1) with one square removed using only the triominoes of Fig 1 removed Figure 1

Proof hint removed Base cases Divide the (2k+1 x 2k+1) checkerboard Into four (2k x 2k) checkerboards Induction hypothesis Assume that the claim holds For boards of size (2k x 2k) Inductive step

Strong induction To prove that is true for all integer We compete two steps: Basis. We verify that the proposition P(1) is true. Inductive Step. We show that the conditional statement Is true for all positive integers k. Inductive hypothesis Inductive hypothesis

Example 1 Theorem. Show that any integer n > 1 can be expressed as the product of one or more primes. (Let us call it P(n)) Basis. P(2) is true. Induction hypothesis. Assume holds Inductive step. We have to show that P (k+1) holds. If P(k+1) is prime, then the theorem holds. Else and a, b < k+1, and due to the induction hypothesis, the theorem holds.

Example 2

Proof using Mathematical Induction

Same Proof using Strong Induction

Errors in Induction Question: What is wrong here?

Errors in Induction Here is a “proof” that a camel can always carry n straws on its back, even if n is arbitrarily large Let P(k) represent “the camel can carry k straws.” Base case: P(1) is true. Induction hypothesis: Assume P(k) is true for some k < n Inductive step: Since the camel can carry k straws, it can carry one more straw, i.e. (k+1) straws, without any problem. Question: What is wrong here?

Recursive definition Recursion means defining or formulating something (such as a function or an algorithm), in terms of itself – For example, let f(x) = x! – We can define f(x) as f(x) = x * f(x-1)

Recursive definition Two parts of a recursive definition: Base case and a Recursive step .

Recursion example

Fibonacci sequence

Bad recursive definitions Why are these definitions bad?

More examples of recursive definitions: defining strings

More examples of recursive definitions: Matched strings of parentheses Data Type Brackets specifies the set of all “matched” sequences of brackets. For example consider [ [ [ ] ] [ ] ] It is matched. 0 +1 +2 +3 +2 +1 +2 +1 0 (The count should never be negative, and must end up with a zero). Base case. Brackets Recursive step. If then

Recursive definition of a full binary tree Basis. A single vertex is a full binary tree Recursive step. If T1 and T2 are disjoint full binary trees, then a full binary tree T1.T2 consisting of a root r and edges connecting r to each of the roots of T1 and T2 is a full binary tree.

Recursive definition of the height of a full binary tree Basis. The height of a full binary tree T consisting of only one node is Recursive step. If T1 and T2 are two full binary trees, then the full binary tree T= T1.T2 has height

Structural induction A technique for proving a property of a recursively defined object. It is very much like an inductive proof, except that in the inductive step we try to show that if the statement holds for each of the element used to construct the new element, then the result holds for the new element too. Example. Prove that if T is a full binary tree, and h(T) is the height of the tree then the number of nodes in the tree n(T) ≤ 2 h(T)+1 -1.

Structural induction continued Prove that if T is a full binary tree, and h(T) is the height of the tree then the number of nodes in the tree n(T) ≤ 2 h(T)+1 -1. root See the textbook (pages 355-356)

Recursive Algorithm Example 1. Given a and n, compute an procedure power (a : real number, n: non-negative integer) if n = 0 then power (a, n) := 1 else power (a, n) := a. power (a, n-1) Revisit Fibonacci, factorial etc.

Recursive Algorithm Example 2. Compute GCD (a,b) a ≤ b) procedure gcd(a, b) if a = 0 then return b else return gcd(b mod a, a)

Recursive algorithms: Sorting Here is the recursive algorithm Merge sort. It merges two sorted Iists to produce a new sorted list 8 2 4 6 10 1 5 3 8 2 4 6 10 1 5 3 8 2 4 6 10 1 5 3

Mergesort The merge algorithm “merges” two sorted lists 2 4 6 8 merged with 1 3 5 10 will produce 1 2 3 4 5 6 8 10 procedure mergesort (L = a1, a2, a3, … an) if n > 0 then m:= ⎣n/2⎦ L1 := a1, a2, a3, … am L2 := am+1, am+2, am+3, … an L := merge (mergesort(L1), mergesort(L2))

Example of Mergesort Completes sorting in O(n log n) steps 1 2 3 4 5 6 8 10 8 2 4 6 10 1 5 3 2 4 6 8 8 2 4 6 10 1 5 3 1 3 5 10 4 6 10 1 5 3 2 8 8 2 4 6 1 10 3 5 Completes sorting in O(n log n) steps

The Merge Algorithm procedure merge(L1,L2 : sorted lists) L := empty list while L1 ≠ empty and L2 ≠ empty remove smaller of first elements of L1 and L2 from its list; put it at the left end of L if this removal makes one list empty then remove all elements from the other list; append them to L return L {L is the merged list with elements in increasing order}

Iteration vs. Recursion Recursive Fibonacci Iterative Fibonacci procedure f (n ≥ 0) if n = 0 then return 0 else if n = 1 then return 1 else return f(n − 1) + f(n − 2) {output is f(n)} procedure f (n ≥ 0) if n = 0 then return 0 else x := 0, y := 1 for i := 1 to n − 1 z := x + y; x := y; y := z return y {output is f(n)} What difference do you see?

Pros and Cons of Recursion While recursive definitions are easy to understand Iterative solutions for Fibonacci sequence are much faster (see page 366)