Discrete Structure Li Tak Sing( 李德成 ) Lecture 13 1.

Slides:



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

Primitive Recursive Functions (Chapter 3)
22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
Discrete Mathematics Math 6A Homework 9 Solution.
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.
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.
CSE115/ENGR160 Discrete Mathematics 03/31/11
Recursion. Recursive Solutions Recursion breaks a problem into smaller identical problems – mirror images so to speak. By continuing to do this, eventually.
Chapter Mathematical Induction
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
Copyright © 2007 Pearson Education, Inc. Slide 8-1 Warm-Up Find the next term in the sequence: 1, 1, 2, 6, 24, 120,…
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,
22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.
Induction and recursion
Recursive Definitions and Structural Induction
1 © 2010 Pearson Education, Inc. All rights reserved 10.1 DEFINITION OF A SEQUENCE An infinite sequence is a function whose domain is the set of positive.
Discrete Mathematics CS 2610 March 26, 2009 Skip: structural induction generalized induction Skip section 4.5.
Induction and recursion
Chapter 4: Induction and Recursion
1 © 2010 Pearson Education, Inc. All rights reserved © 2010 Pearson Education, Inc. All rights reserved Chapter 11 Further Topics in Algebra.
Construction Techniques (2) - 1ICOM 4075 (Spring, 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez 2005.
Section 5.3. Section Summary Recursively Defined Functions Recursively Defined Sets and Structures Structural Induction.
Recursive. 2 Recursive Definitions In a recursive definition, an object is defined in terms of itself. We can recursively define sequences, functions.
1 © 2010 Pearson Education, Inc. All rights reserved © 2010 Pearson Education, Inc. All rights reserved Chapter 10 Further Topics in Algebra.
Copyright © 2011 Pearson Education, Inc. Sequences Section 8.1 Sequences, Series, and Probability.
Lecture#16 Discrete Mathematics. Recursion Now, 1 is an odd positive integer by the definition base. With k = 1, = 3, so 3 is an odd positive integer.
CSE 2813 Discrete Structures Recurrence Relations Section 6.1.
Sequences and Summations
Discrete Structure Li Tak Sing( 李德成 ) Lectures
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
Week 12 - Wednesday.  What did we talk about last time?  Asymptotic notation.
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.
Sequences and Summations Section 2.4. Section Summary Sequences. – Examples: Geometric Progression, Arithmetic Progression Recurrence Relations – Example:
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
Discrete Structures Li Tak Sing ( 李德成 ) Lectures
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
1 Section 3.2 Recursively Defined Functions and Procedures A function ƒ is recursively defined if at least one value ƒ(x) is defined in terms of another.
Foundations of Discrete Mathematics Chapters 5 By Dr. Dalia M. Gil, Ph.D.
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.
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.
Discrete Structures Li Tak Sing( 李德成 ) mt263f ppt 1.
1 Chapter Construction Techniques. 2 Section 3.1 Inductively Defined Sets To define a set S inductively is to do three things: Basis: Specify one.
6/12/2016 Prepared by Dr.Saad Alabbad1 CS100 : Discrete Structures Proof Techniques(2) Mathematical Induction & Recursion Dr.Saad Alabbad Department of.
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
Chapter 6 (Lafore’s Book) Recursion Hwajung Lee.  Definition: An algorithmic technique. To solve a problem on an instance of size n, the instance is:
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.
Fall 2002CMSC Discrete Structures1 Chapter 3 Sequences Mathematical Induction Recursion Recursion.
Chapter 4: Induction and Recursion
Sequences and Series 9.1.
CS2210:0001Discrete Structures Induction and Recursion
Induction and Recursion
Mathematical Induction Recursion
Chapter 5 Induction and Recursion
Discrete Structures for Computer Science
Applied Discrete Mathematics Week 9: Integer Properties
CS 250, Discrete Structures, Fall 2014 Nitesh Saxena
Induction: One Step At A Time
Induction and recursion
Chapter 4 (Part 2): Mathematical Reasoning, Induction & Recursion
Recursion.
Presentation transcript:

Discrete Structure Li Tak Sing( 李德成 ) Lecture 13 1

More examples on inductively defined sets Find an inductive definition for each set S of strings. 1.Even palindromes over the set {a,b} 2.Odd palindromes over the set {a,b} 3.All palindromes over the set {a,b} 4.The binary numerals. 2

Solution 3

More examples on inductively defined sets Find an inductive definition for each set S of lists. 1.{,,,..} 2.{,,,..} 3.{,,,,,,...} 4.{L| L is a list with even length over {0,1,2}} 4

Solution 5

More examples on inductively defined sets Find an inductive definition for the set B of binary trees that represent arithmetic expressions that are either numbers in N or expressions that use operations + or -. 6

Solution 7

More examples on inductively defined sets Find an inductive definition for each subset S of N  N. 1.S={(x,y)| y=x or y=x+1} 2.S={(x,y) | x is even and y  x/2 8

Solution 9

Recursive Functions and Procedures Procedure  A program that performs one or more actions.  A procedure may return one or more values through its argument list. For example, a statement like allocate(m,a,s) might perform the action of allocating a block of m memory cells and return the values a and s, where a is the beginning address of the block and the s tells whether the allocation was successful. 10

Definition of recursively defined A function or a procedure is said to be recursively defined if it is defined in terms of itself. If S is an inductively defined set, then we can construct a function f with domain S as follow:  For each basis element x  S, specify a value for f(x).  Give rules that, for any inductively defined element x  S, will define f(x) in terms of previously defined value of f. 11

Constructing a recursively defined procedure If S if an inductively defined set, we can construct a procedure P to process the elements of S as follows:  For each basis element x  S, specify a set of actions for P(x).  Give rules that, for any inductively defined element x  S, will define the actions of P(x) in terms of previously defined actions of P. 12

Numbers Sum of integers. f(n)= n Definition:  f(n)= if n=0 then 0 else f(n-1)+n  Alternatively, it can be written as f(0)=0 f(n)=f(n-1)+n This is known as the pattern matching method 13

Numbers Adding odd numbers f(n)= (2n+1) Definition:  f(0)=1  f(n)=f(n-1)+(2n+1) 14

The rabbit program The Fibonacci numbers are the numbers in the sequence 0,1,1,2,3,5,8,13 where each number after the first two is computed by adding the preceding two numbers. Assume that at the beginning there is one pair of rabbits. They give birth to another pair of rabbit in one month. Let f(n) represents the number of pairs of rabbits at the n-th month. At that time, there were only f(n-2) mature rabbits which give birth to f(n-2) new rabbits. So the total number of rabbits is the total number of rabbits at the (n-1)th month plus these newly born f(n-2) rabbits. So f(n)=f(n-1)+f(n-2) The sequence 0,1,1,2,3,... is called the Fibonacci numbers. 15

Sum and product notation Sum of sequence a 1,a 2,....,a n Product of a sequence a 1,a 2,....,a n 16

Factorial n!=1  2 .....  n 0!=1 n!=(n-1)!  n 17

Examples Construct a recursive definition for each of the following functions, where all variables are natural numbers. 1.f(n)= n. 2.f(n)=floor(0/2)+floor(1/2)+....+floor(n/2). 3.f(n,k)=k+(k+1)+(k+2)+...+(k+n). 4.f(n,k)=0+k+2k+...+nk. 18

19

Lists f(n)= f(n)= if n=0 then else cons(n,f(n-1)) Using the pattern matching method  f(0)=  f(n)=cons(n, ) =cons(n,f(n-1)) 20

Recursive procedures Let P(n) be the procedure that prints out the numbers in the list. P(n): if n=0 then print(0) else print(n); P(n-1) fi 21

The distribute function dist(3, )= How to define this function recursively? dist(x,L)= if L=<> then <> else (x,head(L))::dist(x,tail(L)) Pattern matching method:  dist(x,<>)=<>  dist(x,a::L)=(x,a)::dist(x,L) 22

The pairs function pairs(, )= pairs(A,B)=if A=B=<> then <> else (head(A),head(B))::pairs(tail(A),tail(B)) pairs(<>,<>)=<>, pairs(x::T, y::U)=(x,y)::pairs(T,U) 23

Concatenation of Lists cat(, )= cat(L,M)=if L=<> then M else head(L)::cat(tail(L),M) Pattern matching method:  cat(<>,A)=A  cat(x::L,A)=x::cat(L,A) 24

Sorting a list by insertion sort(<>)=<> sort(x::L)=insert(x,sort(L)) insert(x,S)=if S=<> then else if x<head(S) then x::s else head(S)::insert(x,tail(S)) 25

Example Write recursive definition for the following list functions. 1.The function "last" that returns the last elemnt of a nonempty list. For example last( )=c 2.The function "front" that returns the list obtained by removing the last element of a nonempty list. For example front( )=. 26

Solution 27