Discrete Structures for Computer Science

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.
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Recursive Definitions and Structural Induction
Recursively Defined Functions
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.
10.1 CompSci 102© Michael Frank Today’s topics RecursionRecursion –Recursively defined functions –Recursively defined sets –Structural Induction Reading:
Induction and recursion
Discrete Structures & Algorithms More about sets EECE 320 — UBC.
CSE115/ENGR160 Discrete Mathematics 04/03/12 Ming-Hsuan Yang UC Merced 1.
Recursive Definitions Rosen, 3.4. Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
CSE115/ENGR160 Discrete Mathematics 03/31/11
Induction and recursion
Recursive Definitions and Structural Induction
Discrete Mathematics CS 2610 March 26, 2009 Skip: structural induction generalized induction Skip section 4.5.
Induction and recursion
Chapter 4: Induction and Recursion
CSE 311 Foundations of Computing I Lecture 15 Recursive Definitions and Structural Induction Autumn 2011 CSE 3111.
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.
March 3, 2015Applied Discrete Mathematics Week 5: Mathematical Reasoning 1Arguments Just like a rule of inference, an argument consists of one or more.
Lecture 4,5 Mathematical Induction and Fibonacci Sequences.
1 Lecture 3.3: Recursion CS 250, Discrete Structures, Fall 2012 Nitesh Saxena Adopted from previous lectures by Cinda Heeren, Zeph Grunschlag.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
1 Recursive Definitions and Structural Induction CS 202 Epp section ??? Aaron Bloomfield.
Inductive Proofs and Inductive Definitions Jim Skon.
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.
Classifications LanguageGrammarAutomaton Regular, right- linear Right-linear, left-linear DFA, NFA Context-free PDA Context- sensitive LBA Recursively.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
CSE 311: Foundations of Computing Fall 2013 Lecture 18: Structural induction, regular expressions.
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
CSE 311 Foundations of Computing I Lecture 15 Strong Induction and Recursive Definitions Spring
Mathematical Induction And Recursion Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
Sequences Lecture 11. L62 Sequences Sequences are a way of ordering lists of objects. Java arrays are a type of sequence of finite size. Usually, mathematical.
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.
Copyright © Zeph Grunschlag,
(Proof By) Induction Recursion
Chapter 4: Induction and Recursion
MATH 224 – Discrete Mathematics
Discrete Structures for Computer Science
Advanced Algorithms Analysis and Design
CS2210:0001Discrete Structures Induction and Recursion
Induction and recursion
Induction and Recursion
CSE 311 Foundations of Computing I
Recursively Defined Functions
Mathematical Induction Recursion
Discrete Structures for Computer Science
Lecture Outline for Recurrences
CSE 311: Foundations of Computing
Induction and recursion
CS 250, Discrete Structures, Fall 2011 Nitesh Saxena
Applied Discrete Mathematics Week 9: Integer Properties
Closure Properties of Regular Languages
CS 250, Discrete Structures, Fall 2015 Nitesh Saxena
CS 250, Discrete Structures, Fall 2014 Nitesh Saxena
Copyright © Zeph Grunschlag,
Advanced Analysis of Algorithms
Mathematical Induction
Math/CSE 1019: Discrete Mathematics for Computer Science Fall 2011
Chapter 4 (Part 2): Mathematical Reasoning, Induction & Recursion
CSE 311 Foundations of Computing I
Recursion.
Presentation transcript:

Discrete Structures for Computer Science Presented By: Andrew F. Conn Lecture #14: Recursion and Structural Induction October 24th, 2016

There are many uses of induction in computer science! Proof by induction is often used to reason about: Algorithm properties (correctness, etc.) Properties of data structures Membership in certain sets Determining whether certain expressions are well-formed … To begin looking at how we can use induction to prove the above types of statements, we first need to learn about recursion

Sometimes, it is difficult or messy to define some object explicitly Recursive objects are defined in terms of themselves We often see the recursive versions of the following types of objects: Functions Sequences Sets Data structures Let’s look at some examples…

Recursive functions are useful When defining a recursive function whose domain is the set of natural numbers, we have two steps: Basis step: Define the behavior of f(0) Recursive step: Compute f(n+1) using f(0), …, f(n) Example: Let f(0) = 3, f(n+1) = 2f(n) + 3 f(1) = 2f(0) + 3 = 2(3) + 3 = 9 f(2) = 2f(1) + 3 = 2(9) + 3 = 21 f(3) = 2f(2) + 3 = 2(21) + 3 = 45 f(4) = 2f(3) + 3 = 2(45) + 3 = 93 … Doesn’t this look a little bit like strong induction?

Some functions can be defined more precisely using recursion Example: Define the factorial function F(n) recursively Basis step: F(0) = 1 Recursive step: F(n+1) = (n+1) × F(n) Note: F(4) = 4 × F(3) = 4 × 3 × F(2) = 4 × 3 × 2 × F(1) = 4 × 3 × 2 × 1 × F(0) = 4 × 3 × 2 × 1 × 1 = 24 Compare the above definition our old definition: F(n) = n × (n-1) × … × 2 × 1 The recursive definition avoids using the “…” shorthand!

It should be no surprise that we can also define recursive sequences Example: The Fibonacci numbers, {fn}, are defined as follows: f0 = 1 f1 = 1 fn = fn-1 + fn-2 Calculate: f2, f3, f4, and f5 f2 = f1 + f0 = 1 + 1 = 2 f3 = f2 + f1 = 2 + 1 = 3 f4 = f3 + f2 = 3 + 2 = 5 f5 = f4 + f3 = 5 + 3 = 8 This gives us the sequence {fn} = 1, 1, 2, 3, 5, 8, 13, 21, 34, … This is like strong induction, since we need more than fn-1 to compute fn. Fib numbers in nature

Recursion is used heavily in the study of strings Let: ∑ be defined as an alphabet Binary strings: ∑ = {0, 1} Lower case letters: ∑ = {a, b, c, …, z} We can define the set ∑* containing all strings over the alphabet ∑ as follows: Basis step: λ ∈ ∑* Recursive step: If w ∈ ∑* and x ∈ ∑, then wx ∈ ∑* Example: If ∑ = {0, 1}, then ∑ = {λ, 0, 1, 01, 11, …} λ is the empty string containing no characters

We can define sets of well-formed formulae recursively This is often used to specify the operations permissible in a given formal language (e.g., a programming language) Example: Defining propositional logic Basis step: T, F, and s are well-formed propositional logic statements (where s is a propositional variable) Recursive step: If E and F are well-formed statements, so are (¬E) (E ∧ F) (E ∨ F) (E → F) (E ↔ F)

✔ Example Question: Is ((p ∧ q) → (((¬r) ∨ q) ∧ t)) well-formed? Basis tells us that p, q, r, t are well-formed 1st application: (p ∧ q), (¬r) are well-formed 2nd application: ((¬r) ∧ q) is well-formed 3rd application: (((¬r) ∨ q) ∧ t) 4th application: ((p ∧ q) → (((¬r) ∨ q) ∧ t)) is well-formed Note: You will learn more about this in CS 1511! ✔

Group work! Problem 1: Construct a recursive definition of the sequence {an} where the nth term is a natural number computed by adding the (n-1)st term to twice the (n-3)rd term. Assume that the first three terms of this sequence are 1, 1, 1. Problem 2: Construct a recursive definition of the function r() that reverses a string. E.g., r(cat) = tac.

Like other forms of induction, structural induction requires that we consider two cases Basis step: Show that the result holds for the objects specified in the basis case of the recursive definition Recursive step: Show that if the result holds for the objects used to construct new elements using the recursive step of the definition, then it holds for the new object as well. Note: Many problems with structural induction deal with data structures you have not learned yet.

Let’s discuss family trees Consider a family tree where each node can have at most 2 known parents: Charles Ellen John Ann Frank Mary Andrew

Properties of the family tree Let’s call the generations of the tree 𝑛. Thus in the example tree, Andrew is 3rd generation. Assume that ancestors can be forgotten. This allows for “unbalanced” trees. For example, suppose Mary forgot her mother and father. How many people can a family tree of 𝑛 generations have? It can have at most 2 𝑛 −1 people.

Lets prove it! 𝑃 𝑛 ≡ A family tree with 𝑛 generations has at most 2 𝑛 −1 people. ✔ Base case: 𝑃(1): 2 1 −1=1 I.H.: Assume that 𝑃(𝑘) holds for a family tree of 𝑘 generations The family tree with 𝑘+1 generations has at most 2 ancestry trees before it with 𝑘 generations. By I.H. each ancestry tree has 2 𝑘 −1 people. Then the current ancestry tree has 2 2 𝑘 −1 +1 people. (Two ancestry trees plus the current person) 2 2 𝑘 −1 +1=2∙ 2 𝑘 −2+1= 2 𝑘+1 −1 Inductive step: We will now show that 𝑃(𝑘) → 𝑃(𝑘+1) Conclusion: Since we have proved the base case and the inductive case, the claim holds by structural induction ❏

Data Structures Many common and important Data Structures in Computer Science have recursive definitions. I highly encourage you to come back to this material after you have taken a Data Structures course. For now we are going to move on.

Multiples of 3 Consider the recursively defined set: 3∈𝑆 𝑥∈𝑆∧𝑦∈𝑆 → 𝑥+𝑦 ∈𝑆 What are some elements of 𝑆? Clearly 3∈𝑆 6∈𝑆 because 6=3+3 ∧ 3∈𝑆 So, 9∈𝑆 In fact: 𝑆= 3,6,9,…,3𝑛 𝑛∈ℕ =3ℕ

Let’s prove it! First, we’ll prove that 3ℕ⊆𝑆 ✔ 𝑃 𝑛 ≡3𝑛∈𝑆 ∀𝑛∈ℕ Base case: 𝑃 1 : 3∈𝑆 by definition I.H.: Assume that 𝑃(𝑘) holds for an arbitrary integer 𝑘 Inductive step: We will now show that 𝑃(𝑘)→𝑃(𝑘+1) 3𝑘∈𝑆 by I.H. 3 ∈ 𝑆 by definition 3𝑘+3∈𝑆 by recursive definition of 𝑆 3(𝑘+1)∈𝑆 Conclusion: Since we have proved the base case and the inductive case, 3ℕ⊆𝑆 ❏

Proving the converse! Now, we’ll prove that 𝑆⊆3ℕ ✔ 𝑃 𝑛 : All numbers generated using 𝑛 applications of the recursive definition of 𝑆 are of the form 3𝑗. ✔ Base case: 𝑃 0 : 3∈𝑆 by base case for 𝑆, and 3=3∙1. I.H.: Assume that 𝑃 𝑘 holds for an arbitrary integer 𝑘 Assume that 𝑥 and 𝑦 are elements of 𝑆, 𝑥 is generated using 𝑘 applications of the recursive definition of 𝑆, and 𝑦 is generated using no more than 𝑘 applications of the recursive definition of 𝑆 Therefore, 𝑥+𝑦∈𝑆 after 𝑘+1 applications of 𝑆’s definition Since 𝑥=3 𝑗 𝑥 and 𝑦=3 𝑗 𝑦 by the I.H., 𝑥+𝑦=3( 𝑗 𝑥 + 𝑗 𝑦 ) Thus 𝑥+𝑦∈3ℕ Inductive step: We will now show that 𝑃 𝑘 →𝑃 𝑘+1 Conclusion: Since we have proved the base case and the inductive case, S ⊆ A ❏ Since S ⊆ A and A ⊆ S, the claim holds.

Final Thoughts Structural induction can be used to prove properties of recursive Functions Sequences Sets Data structures Next time, we start learning about counting and combinatorics (Section 6.1)