CS 250, Discrete Structures, Fall 2014 Nitesh Saxena

Slides:



Advertisements
Similar presentations
Recursive Definitions and Structural Induction
Advertisements

Copyright © Zeph Grunschlag, Recursion Zeph Grunschlag.
1 Section 3.4 Recursive Definitions. 2 Recursion Recursion is the process of defining an object in terms of itself Technique can be used to define sequences,
Discrete Mathematics CS 2610 March 26, 2009 Skip: structural induction generalized induction Skip section 4.5.
Induction and recursion
Lecture 3.1: Mathematical Induction CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag.
Section 5.3. Section Summary Recursively Defined Functions Recursively Defined Sets and Structures Structural Induction.
Recursion. L162 Agenda Recursion and Induction Recursive Definitions Sets Strings.
CS Discrete Mathematical Structures Mehdi Ghayoumi MSB rm 132 Ofc hr: Thur, 9:30-11:30a.
Lecture 3.4: Recursive Algorithms CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag.
1 Lecture 3.3: Recursion CS 250, Discrete Structures, Fall 2012 Nitesh Saxena Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag.
Lecture 4.3: Closures and Equivalence Relations CS 250, Discrete Structures, Fall 2013 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
Lecture 6.1: Misc. Topics: Number Theory CS 250, Discrete Structures, Fall 2011 Nitesh Saxena.
Lecture 4.1: Relations Basics CS 250, Discrete Structures, Fall 2012 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.
Lecture 2.5: Sequences CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Zeph Grunschlag.
Lecture 1.4: Rules of Inference, and Proof Techniques* CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Cinda Heeren.
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.
9/13/2011Lecture Sequences1 Lecture 2.5: Sequences* CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph.
Discrete Mathematics Lecture # 22 Recursion.  First of all instead of giving the definition of Recursion we give you an example, you already know the.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
Lecture 1.5: Proof Techniques CS 250, Discrete Structures, Fall 2012 Nitesh Saxena Adopted from previous lectures by Cinda Heeren 1.
9/29/2011Lecture Strong Induction1 Lecture 3.2: Strong Induction CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures.
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
Mathematical Induction And Recursion Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
Fall 2002CMSC Discrete Structures1 Chapter 3 Sequences Mathematical Induction Recursion Recursion.
9/27/2011 Lecture Mathematical Induction1 Lecture 3.1: Mathematical Induction* CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from.
Lecture 3.4: Recursive Algorithms CS 250, Discrete Structures, Fall 2015 Nitesh Saxena Adopted from previous lectures by Zeph Grunschlag.
Lecture 1.5: Proof Techniques
Copyright © Zeph Grunschlag,
Chapter 4: Induction and Recursion
Lecture 5.4: Paths and Connectivity
Lecture 4.1: Relations Basics
Lecture 1.5: Proof Techniques
Lecture 4.3: Closures and Equivalence Relations
GCD and Optimization Problem
Lecture 3.2: Induction and Strong Induction (contd.)
Mathematical Induction Recursion
VCU, Department of Computer Science CMSC 302 Sequences and Summations Vojislav Kecman 9/19/2018.
Discrete Structures for Computer Science
ICS 253: Discrete Structures I
Lecture 4.1: Relations Basics
Lecture 3.2: Induction, and Strong Induction
CS 250, Discrete Structures, Fall 2015
CS 250, Discrete Structures, Fall 2011 Nitesh Saxena
Lecture 3.2: Induction and Strong Induction (contd.)
CS 250, Discrete Structures, Fall 2014
Lecture 3.2: Induction, and Strong Induction
CS 250, Discrete Structures, Fall 2013
CS 250, Discrete Structures, Fall 2015
Lecture 4.3: Closures and Equivalence Relations
Applied Discrete Mathematics Week 9: Integer Properties
Lecture 3.2: Induction, and Strong Induction
Lecture 1.6: Proof Techniques (contd)
CS 250, Discrete Structures, Fall 2015 Nitesh Saxena
Lecture 2.1: Sets and Set Operations*
CS 250, Discrete Structures, Fall 2013
Lecture 3.1: Mathematical Induction
Lecture 4.1: Relations Basics
CS 250, Discrete Structures, Fall 2014 Nitesh Saxena
Copyright © Zeph Grunschlag,
Lecture 1.6: Proof Techniques (contd)
Copyright © Zeph Grunschlag,
Lecture 5.3: Graph Isomorphism and Paths
CS 250, Discrete Structures, Fall 2014 Nitesh Saxena
Chapter 4 (Part 2): Mathematical Reasoning, Induction & Recursion
Lecture 3.1: Mathematical Induction
CS 250, Discrete Structures, Fall 2015 Nitesh Saxena
CS 250, Discrete Structures, Fall 2015 Nitesh Saxena
CS 250, Discrete Structures, Fall 2012
Presentation transcript:

CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Lecture 3.3: Recursion CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag

Course Admin Mid-Term 1 Graded To be distributed today HW2 being graded Solution provided 4/7/2019 Lecture 3.3 -- Recursion

Lecture 3.2: Induction and Strong Induction (contd) Course Admin Overall grades Recall: they will be relative, based on overall performance of the class Further improvement possible in the upcoming HWs and two exams Please continue to work hard. It will pay off. Don’t hesitate to ask for extra help 4/7/2019 Lecture 3.2: Induction and Strong Induction (contd)

Course Admin HW3 posted Mid Term 2: Nov 4 (Tues) Covers “Induction and Recursion” (Chapter 5) Due in Thu, Nov 6 Mid Term 2: Nov 4 (Tues) Review Oct 30 (Thu) 4/7/2019 Lecture 3.3 -- Recursion

Outline Some practice: strong induction Recursion Recursive Functions and Definitions 4/7/2019 Lecture 3.3 -- Recursion

Strong Induction Example (Rosen) Prove that every integer > 1 can be expressed as a product of prime numbers [This is referred to as the fundamental theorem of arithmetic] 4/7/2019 Lecture 3.3 -- Recursion

Recursively Defined Sequences Often it is difficult to express the members of an object or numerical sequence explicitly. EG: The Fibonacci sequence: {fn } = 0,1,1,2,3,5,8,13,21,34,55,… There may, however, be some “local” connections that can give rise to a recursive definition –a formula that expresses higher terms in the sequence, in terms of lower terms. EG: Recursive definition for {fn }: INITIALIZATION: f0 = 0, f1 = 1 RECURSION: fn = fn-1+fn-2 for n > 1. 4/7/2019 Lecture 3.3 -- Recursion

Recursive Functions It is possible to think of any function with domain N as a sequence of numbers, and vice-versa. Simply set: fn =f (n) For example, our Fibonacci sequence becomes the Fibonacci function as follows: f (0) = 0, f (1) = 1, f (2) = 1, f (3) = 2,… Such functions can then be defined recursively by using recursive sequence definition. EG: INITIALIZATION: f (0) = 0, f (1) = 1 RECURSION: f (n) = f (n -1) +f (n -2), for n > 1. 4/7/2019 Lecture 3.3 -- Recursion

Recursive Functions: Factorial A simple example of a recursively defined function is the factorial function: n! = 1· 2· 3· 4 ···(n –2)·(n –1)·n i.e., the product of the first n positive numbers (by convention, the product of nothing is 1, so that 0! = 1). Q: Find a recursive definition for n! 4/7/2019 Lecture 3.3 -- Recursion

Recursive Functions: Factorial A:INITIALIZATION: 0!= 1 RECURSION: n != n · (n -1)! To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case. EG: 5! = 4/7/2019 Lecture 3.3 -- Recursion

Recursive Functions: Factorial A:INITIALIZATION: 0!= 1 RECURSION: n != n · (n -1)! To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case. EG: 5! = 5 · 4! = 5 · 4 · 3! = 5 · 4 · 3 · 2! = 5 · 4 · 3 · 2 · 1! = 5 · 4 · 3 · 2 · 1 · 0! = 120 4/7/2019 Lecture 3.3 -- Recursion

Recursive Functions: gcd Euclid’s algorithm makes use of the fact that gcd(x,y ) = gcd(y, x mod y) (here we assume that x > 0) 4/7/2019 Lecture 3.3 -- Recursion

Recursive Definitions: Mathematical Notation Definition of summation notation: There is also a general product notation : 4/7/2019 Lecture 3.3 -- Recursion

Recursive Definitions: Mathematical Notation Q: Find a recursive definition for the product notation 4/7/2019 Lecture 3.3 -- Recursion

Recursive Definitions: Mathematical Notation A: This is very similar to definition of summation notation. Note: Initialization is argument for “product of nothing” being 1, not 0. 4/7/2019 Lecture 3.3 -- Recursion

Recursively Defined Sets Our examples so far have been inductively defined functions. Sets can be defined inductively, too. Give an inductive definition of S = {x: x is a multiple of 3} 3  S x,y  S  x + y  S Base Case Recursive Case 4/7/2019 Lecture 3.3 -- Recursion

Strings: Recursive Definition Let  be a finite set called an alphabet. The set of strings on , denoted * is defined as:   *, where  denotes the null or empty string. If x  , and w  *, then wx  *, where wx is the concatenation of string w with symbol x. Example: Let  = {a, b, c}. Then * = {, a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc, aaa, aab,…} How big is *? Countably infinite 4/7/2019 Lecture 3.3 -- Recursion

Length of a String: Recursive Definition Recursive definition of the length of strings (the length of string w is |w|.): || = 0 If x  , and w  *, then |wx| = |w| + 1 4/7/2019 Lecture 3.3 -- Recursion

Well Formed Formulae (WFF) for Propositions A set of wff is defined as follows: T is a wff F is a wff p is a wff for any propositional variable p If p is a wff, then (p) is a wff If p and q are wffs, then (p  q), is a wff If p and q are wffs, then (p  q) is a wff For example, a statement like ((r)  (p  r)) can be proven to be a wff by arguing that (r) and (p  r) are wffs by recursion and then applying rule 5. 4/7/2019 Lecture 3.3 -- Recursion

Today’s Reading Rosen 5.3 4/7/2019 Lecture 3.3 -- Recursion