Discrete Structures CMSC 2123 Lecture 27 5.3 Recursive Definitions and Structural Induction Introduction recursion A definition that defines an object in terms of itself. Recursively Defined Functions Two steps are employed to define a function with the set of nonnegative integers as its domain: 1. BASIS STEP: Specify the value of the function at zero. 2. RECURSIVE STEP: Give a rule for finding its value at an integer from its values at smaller integers. EXAMPLE 1 EXAMPLE 2 Suppose that f is defined recursively by ππ(0) = 3. ππ(ππ + 1) = 2ππ(ππ) + 3. Find ππ(1), ππ(2), ππ(3) and ππ(4). Solution: ππ(1) = 2ππ(0) + 3 ππ(2) = 2ππ(1) + 3 ππ(3) = 2ππ(2) + 3 ππ(4) = 2ππ(3) + 3 EXAMPLE 3 Give an inductive definition of the factorial function πΉπΉ(ππ) = ππ!. Solution: 1. BASIS STEP: πΉπΉ(0) = 1 2. RECURSIVE STEP: πΉπΉ(ππ + 1) = (ππ + 1) β πΉπΉ(ππ) EXAMPLE 4 Give a recursive definition of 9 21 45 93 Give an inductive definition of the function ππππ , where a is a nonzero real number an n is a nonnegative integer. Solution: 1. BASIS STEP: ππ(0) = 1, ππ0 = 1 2. RECURSIVE STEP: ππ(ππ + 1) = ππ β ππ(ππ), ππππ+1 = ππ β ππππ ππ οΏ½ ππππ ππ=0 Solution: 1. β0ππ=0 ππππ = ππ0 ππ 2. βππ+1 ππ=0 ππππ = (βππ=0 ππππ ) + ππππ+1 1 Discrete Structures CMSC 2123 DEFINITION 1 Lecture 27 5.3 Recursive Definitions and Structural Induction The Fibonacci numbers, ππ0 , ππ1 , ππ2 , β―, are defined by the equations ππ0 = 0 and ππ1 = 1, and ππππ = ππππβ1 + ππππβ2 EXAMPLE 5 for ππ = 2, 3, 4 , β― Find the Fibonacci numbers ππ2 , ππ3 , ππ4 , ππ5 , and ππ6 . Solution: ππ2 = ππ1 + ππ0 = 1+0= ππ3 = ππ2 + ππ1 = 1+1= ππ4 = ππ3 + ππ2 = 2+1= ππ5 = ππ4 + ππ3 = 3+2= ππ6 = ππ5 + ππ4 = 5+3= 2 1 2 3 5 8
© Copyright 2025 Paperzz