Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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 in terms of itself. This process is called recursion. FIGURE 1 A Recursively Defined Picture. 1

2 Recursively Defined Functions We use two steps to define a function with the set of nonnegative integers as its domain: Basis step: specify the value of the function at zero. Recursive step: give a rule for finding its value at an integer from its values at smaller integers. Such a definition is called a recursive or inductive definition. Example 1: suppose that f is defined recursively by f(0)=3, f(n+1)=2*f(n) +3. find f(1), f(2), f(3), f(4). 2

3 Example 2: give an inductive definition of the factorial function F(n)=n!. Example 3: Give a recursive definition of a n, where a is a nonzero real number and n is a nonnegative integer. Example 4: Give a recursive definition of 3 Recursively Defined Functions

4 Definition 1: The Fibonacci numbers, f 0, f 1,f 2,..., are defined by the equations: f 0 =0, f 1 =1, and f n = f n-1 + f n-2 for n = 2, 3, 4,... Example 5: Find the Fibonacci numbers f 2, f 3, f 4, f 5, and f 6. Example 6: Show that whenever n ≥ 3, f n > α n-2, where 4 Recursively Defined Functions

5 Recursively Defined Sets and Structures Example 7: consider the subset S of the set of integers defined by Basis step: 3 S. Recursive step: if x S, y S, then x+y S. 5

6 Definition 2: The set  * of strings over the alphabet  can be defined recursively by Basis step:  * (where λ is the empty string containing no symbols) Recursive step: if w  * and x , then wx  * Example 8: if  ={0, 1}, the strings found to be in  *, the set of all bit strings, are 1.λ specified to be in the basis step, 2.0 and 1 formed during the first application of the recursive step, 3.00, 01, 10, and 11 formed during the second application for the recursive step, and so on. 6 Recursively Defined Sets and Structures

7 Definition 3: two strings can be combined via the operation of concatenation. Let  be a set of symbols and  * the set of strings formed form 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 w 1  * and w 2  * and x , then w 1 ∙(w 2 x)=(w 1 ∙ w 2 )x Example 9: length of a string Give a recursive definition of l(w), the length of the string w. 7 Recursively Defined Sets and Structures

8 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 T 1, T 2,...,T n are disjoint rooted trees with roots r 1, r 2,..., r n, respectively. Then the graph formed by staring with a root r, which is not in any of the rooted trees T 1, T 2,...,T n, and adding an edge from r to each of the vertices r 1, r 2,..., r n, is also a rooted tree. 8 Recursively Defined Sets and Structures

9 FIGURE 2 Building Up Rooted Trees. 9 Recursively Defined Sets and Structures

10 Definition 5: The set of extended binary trees can be defined recursively by these step: Basis step: The empty set is an extended binary tree. Recursive step: if T 1 and T 2 are disjoint extended binary trees, there is an extended binary tree, denoted by T 1 ∙ T 2, consisting of a root r together with edges connecting the root to each of the roots of the left subtree T 1 and the right subtree T 2 when these trees are nonempty. 10 Recursively Defined Sets and Structures

11 FIGURE 3 Building Up Extended Binary Trees. 11 Recursively Defined Sets and Structures

12 Definition 6: The set of full binary trees can be defined recursively by these steps: Basis step: There is a full binary tree consisting only of a single vertex r. Recursive step: if T 1 and T 2 are disjoint full binary trees, there is a full binary tree, denoted by T 1 ∙ T 2, consisting of a root r together with edges connecting the root to each of the roots of the left subtree T 1 and the right subtree T 2. 12 Recursively Defined Sets and Structures

13 FIGURE 4 Building Up Full Binary Trees. 13 Recursively Defined Sets and Structures

14 Structural Induction To prove results about recursively defined sets we generally use some form of mathematical induction. Example 12: show that the set S defined in example 7 by specifying that 3 S and that if x S and y S, then x+y S, is the set of all positive integers that are multiples of 3. 14

15 Structural Induction Definition 7: We define the height and number of vertex, h(T) and n(T), of a full binary tree T recursively,. Basis step: The height of the full binary tree T consisting of only a root r is h(T)=0 Recursive step: If T 1 and T 2 are full binary trees, then the full binary tree T= T 1 ∙T 2 has height h(T) = 1+ max(h(T 1 ), h(T 2 )), n(T) = 1+n(T 1 )+n(T 2. Theorem 2: If T is a full binary tree T, then n(T) ≤ 2 h(T) +1 -1 15

16 Generalized Induction As an example, note that we can define an ordering on N x N, the ordered pairs of nonnegative integers, by specifying that (x1, y1) is less than or equal to (x2, y2) if either x1< x2, or x1=x2 and y1 < y2; this is called the lexicographic ordering. The set N x N with this ordering has the property that every subset of N x N has a least element (see Supplementary exercise 53 in section 8.6). This implies that we can recursively define the terms a m,n, with m  N, n  N, and prove results about them using a variant of mathematical induction, as illustrated in example 15. 16

17 Generalized Induction Example 15: Suppose that a m,n is defined recursively for (m, n)  N x N by a 0,0 =0 and Show that a m,n =m+n(n+1)/2 for all (m, n) NxN that is, for all pairs of nonnegative integers. 17


Download ppt "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."

Similar presentations


Ads by Google