Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 (Part 2): Mathematical Reasoning, Induction & Recursion

Similar presentations


Presentation on theme: "Chapter 4 (Part 2): Mathematical Reasoning, Induction & Recursion"— Presentation transcript:

1 Chapter 4 (Part 2): Mathematical Reasoning, Induction & Recursion
CSE 504 Discrete Structures & Foundations of Computer Science Dr. Djamel Bouchaffra Chapter 4 (Part 2): Mathematical Reasoning, Induction & Recursion Recursive Definitions (3.4) Ch. 3 (Part 2): Sections 3.4

2 Introduction Define an object in terms of itself: this process is called recursion CS 210 Discrete Structures, Chapter 4 (Part 2)

3 Introduction (cont.) We can use recursion to define sequences, functions and sets Example: the sequence of powers of 2 is given by an = 2n for n = 0, 1, 2, … (explicitly defined) a0 = 1; an+1 = 2an for n = 0, 1, 2, … (recursively defined) CS 210 Discrete Structures, Chapter 4 (Part 2)

4 Recursively Defined Functions
We use 2 steps to define a function recursively: Basis step: specify the the value of the function at 0 Recursive step: give a rule for determining its value at an integer from its value at smaller integers Such a definition is called a recursive or induction definition CS 210 Discrete Structures, Chapter 4 (Part 2)

5 Recursively Defined Functions (cont.)
Example: f defined recursively as: f(0) = 3 f(n + 1) = 2 f(n) + 3 determine f(1), f(2), f(3) and f(4) Solution: by definition: f(1) = 2f(0) + 3 = 2 * = 9 f(2) = 2f(1) + 3 = 2 * = 21 f(3) = 2f(2) + 3 = 2 * = 45 f(4) = 2f(3) + 3 = 2 * = 93 CS 210 Discrete Structures, Chapter 4 (Part 2)

6 Recursively Defined Functions (cont.)
Example: Give an inductive definition of f(n) = n! Solution: Basis step: Specify the initial value of this function; f(0) = 1. Recursive step: give a rule for determining f(n + 1) from f(n) (n + 1)! = (n + 1) * n!  f(n + 1) = (n + 1)*f(n) CS 210 Discrete Structures, Chapter 4 (Part 2)

7 Recursively Defined Functions (cont.)
Example: Give a recursive definition of Solution: Basis step: Recursive step: CS 210 Discrete Structures, Chapter 4 (Part 2)

8 Recursively Defined Functions (cont.)
Definition 1: The Fibonacci numbers, f0, f1, f2, …, are defined by the equations f0 = 0, f1 = 1, and fn = fn-1 + fn-2 for n = 2, 3, 4, … CS 210 Discrete Structures, Chapter 4 (Part 2)

9 Recursively Defined Functions (cont.)
Example: Determine the Fibonacci numbers f2, f3, f4, f5 and f6 Solution: Basis step: f0 = 0 and f1 = 1 Recursive step: fn = fn-1 + fn-2  f2 = f1 + f0 = = 1 f3 = f2 + f1 = = 2 f4 = f3 + f2 = = 3 f5 = f4 + f3 = = 5 f6 = f5 + f4 = = 8 Recursively defined sets and structures. CS 210 Discrete Structures, Chapter 4 (Part 2)

10 Recursively Defined Functions (cont.)
Question: How can sets be defined recursively? Example: Consider the subset S of the set of integers defined by: Basis step: 3  S Recursive steps: if x  S  y  S  x + y  S. 3  S (basis step) 3  S  3  S  = 6  S (recursive step) 6  S  3  S  = 9  S (recursive step) 6  S  6  S  = 12  S (recursive step) CS 210 Discrete Structures, Chapter 4 (Part 2)

11 Recursively Defined Functions (cont.)
Definition 2: The set * of strings over the alphabet  can be defined by Basis step:   * (where  is the empty string containing no symbols) Recursive step: if w  * and x  , then wx  *. Example: if  = {0, 1} Basis step:   * Recursive step: 0, 1 (0  *, 1  *) Recursive step:  * CS 210 Discrete Structures, Chapter 4 (Part 2)

12 Recursively Defined Functions (cont.)
Definition 3 Two strings can be combined via the operation of concatenation. Let  be a set of symbols and * the set of strings formed from symbols in . We can define the concatenation of two strings, denoted by  recursively as follows: Basis step: if w  *, then w   = w, where  is the empty string. Recursive step: if w1  *, w2  * and x  , then w1  (w2x) = (w1  w2) x. Example: w1= abra w2 = cadabra w1w2 = abracadabra

13 Recursively Defined Functions (cont.)
Definition 4 The set of rooted trees, where a rooted tree consists of a set of vertices containing a distinguished vertex called the root, and edges connecting these vertices, can be defined recursively by these steps: Basis step: a single vertex r is a rooted tree. Recursive step: Suppose that T1, T2, …, Tn are rooted trees with roots r1, r2, …, rn, respectively. Then the graph formed by starting with a root r, which is not in any of the rooted trees T1, T2, …, Tn , and adding an edge from r to each of the vertices r1, r2, …, rn, is also a rooted tree. CS 210 Discrete Structures, Chapter 4 (Part 2)

14 Building up rooted trees
Basis step Step 1 Step 2


Download ppt "Chapter 4 (Part 2): Mathematical Reasoning, Induction & Recursion"

Similar presentations


Ads by Google