Today s topics. 3.4: Recursive Definitions. Recursively Defined Functions. Simplest case: One way to define a. a n =f(n) ) is to: Define f(0).

Similar documents
Mathematical Induction. Lecture 10-11

Full and Complete Binary Trees

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

Mathematics for Computer Science/Software Engineering. Notes for the course MSM1F3 Dr. R. A. Wilson

Section IV.1: Recursive Algorithms and Recursion Trees

Basic Proof Techniques

Data Structures Fibonacci Heaps, Amortized Analysis

3. Mathematical Induction

Introduction. Appendix D Mathematical Induction D1

Recursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1

CS 103X: Discrete Structures Homework Assignment 3 Solutions

8 Divisibility and prime numbers

Automata and Formal Languages

8 Primes and Modular Arithmetic

Undergraduate Notes in Mathematics. Arkansas Tech University Department of Mathematics

CHAPTER 5. Number Theory. 1. Integers and Division. Discussion

SECTION 10-2 Mathematical Induction

Sample Induction Proofs

God created the integers and the rest is the work of man. (Leopold Kronecker, in an after-dinner speech at a conference, Berlin, 1886)

ML for the Working Programmer

Reading 13 : Finite State Automata and Regular Expressions

Continued Fractions and the Euclidean Algorithm

MATH 289 PROBLEM SET 4: NUMBER THEORY

GRAPH THEORY LECTURE 4: TREES

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

MATH10040 Chapter 2: Prime and relatively prime numbers

Regular Languages and Finite Automata

Cartesian Products and Relations

Proseminar on Semantic Theory Fall 2013 Ling 720. Problem Set on the Formal Preliminaries : Answers and Notes

The Goldberg Rao Algorithm for the Maximum Flow Problem

Geometric Transformations

Core Maths C1. Revision Notes

Discrete Mathematics Problems

GREATEST COMMON DIVISOR

Homework until Test #2

Math 55: Discrete Mathematics

Midterm Practice Problems

Quotient Rings and Field Extensions

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

NUMBER SYSTEMS. William Stallings

Catalan Numbers. Thomas A. Dowling, Department of Mathematics, Ohio State Uni- versity.

STUDENT S SOLUTIONS MANUAL ELEMENTARY NUMBER THEORY. Bart Goddard. Kenneth H. Rosen AND ITS APPLICATIONS FIFTH EDITION. to accompany.

We can express this in decimal notation (in contrast to the underline notation we have been using) as follows: b + 90c = c + 10b

MATH 22. THE FUNDAMENTAL THEOREM of ARITHMETIC. Lecture R: 10/30/2003

Answer Key for California State Standards: Algebra I

Computing exponents modulo a number: Repeated squaring

INCIDENCE-BETWEENNESS GEOMETRY

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

1. Prove that the empty set is a subset of every set.

SECTION 10-5 Multiplication Principle, Permutations, and Combinations

CS 3719 (Theory of Computation and Algorithms) Lecture 4

Lecture 17 : Equivalence and Order Relations DRAFT

HOMEWORK 5 SOLUTIONS. n!f n (1) lim. ln x n! + xn x. 1 = G n 1 (x). (2) k + 1 n. (n 1)!

Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:

6.3 Conditional Probability and Independence

Automata Theory. Şubat 2006 Tuğrul Yılmaz Ankara Üniversitesi

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

Handout NUMBER THEORY

DEGREES OF CATEGORICITY AND THE HYPERARITHMETIC HIERARCHY

1 if 1 x 0 1 if 0 x 1

CHAPTER 3. Methods of Proofs. 1. Logical Arguments and Formal Proofs

Cardinality. The set of all finite strings over the alphabet of lowercase letters is countable. The set of real numbers R is an uncountable set.

The Ideal Class Group

Mathematical Induction

CHAPTER 7 GENERAL PROOF SYSTEMS

V. Adamchik 1. Graph Theory. Victor Adamchik. Fall of 2005

Examination paper for MA0301 Elementær diskret matematikk

Zeros of Polynomial Functions

Zeros of a Polynomial Function

COMPUTER SCIENCE. Paper 1 (THEORY)

Properties of Stabilizing Computations

Arkansas Tech University MATH 4033: Elementary Modern Algebra Dr. Marcel B. Finan

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

Handout #1: Mathematical Reasoning

Chapter 7 - Roots, Radicals, and Complex Numbers

Mathematical Methods of Engineering Analysis

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Lecture 16 : Relations and Functions DRAFT

Computational Models Lecture 8, Spring 2009

Graph Theory Problems and Solutions

Fundamentele Informatica II

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013

CONTINUED FRACTIONS AND PELL S EQUATION. Contents 1. Continued Fractions 1 2. Solution to Pell s Equation 9 References 12

Notes on Determinant

I. GROUPS: BASIC DEFINITIONS AND EXAMPLES

Indiana State Core Curriculum Standards updated 2009 Algebra I

Calculate Highest Common Factors(HCFs) & Least Common Multiples(LCMs) NA1

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Section 4.2: The Division Algorithm and Greatest Common Divisors

SOLUTIONS FOR PROBLEM SET 2

LAKE ELSINORE UNIFIED SCHOOL DISTRICT

C H A P T E R Regular Expressions regular expression

Functions Recursion. C++ functions. Declare/prototype. Define. Call. int myfunction (int ); int myfunction (int x){ int y = x*x; return y; }

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. !-approximation algorithm.

Zeros of Polynomial Functions

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 4 Nancy Lynch

The Halting Problem is Undecidable

CS103B Handout 17 Winter 2007 February 26, 2007 Languages and Regular Expressions

The last three chapters introduced three major proof techniques: direct,

An example of a computable

Transcription:

Today s topics 3.4: Recursive Definitions Recursion Recursively defined functions Recursively defined sets Structural Induction Reading: : Sections 3.4 Upcoming Counting In induction, we prove all members of an infinite set satisfy some predicate P by: proving the truth of the predicate for larger members in terms of that of smaller members. In recursive definitions,, we similarly define a function, a predicate, a set, or a more complex structure over an infinite domain (universe of discourse) by: defining the function, predicate value, set membership, or structure of larger elements in terms of those of smaller ones. In structural induction,, we inductively prove properties of recursively-defined objects in a way that parallels the objects own recursive definitions. 10.1 10.2 Recursion Recursively Defined Functions Recursion is the general term for the practice of defining an object in terms of itself or of part of itself This may seem circular, but it isn t t necessarily. An inductive proof establishes the truth of P(n+1) recursively in terms of P(n). There are also recursive algorithms, definitions, functions, sequences, sets,, and other structures. Simplest case: One way to define a function f:n!s (for any set S) ) or series a n =f(n) ) is to: Define f(0). For n>0, define f(n) ) in terms of f(0), (0),,f(n!1). E.g.: : Define the series a n :" 2 n recursively: Let a 0 :" 1. For n>0, let a n :" 2a n-1-1. 10.3 10.4

Another Example Recursive definition of Factorial Suppose we define f(n) ) for all n#n recursively by: Let f(0)=3 For all n#n,, let f(n+1)=2 +1)=2f(n)+3)+3 What are the values of the following? f(1)= 9 f(2)= 21 f(3)= 45 f(4)= 93 Give an inductive (recursive) definition of the factorial function, F(n) ) :": n!! :": & 1#i"n i = 1"2" "n. Base case: F(0) :" 1 Recursive part: F(n) :" n " F(n!1). F(1)=1 F(2)=2 F(3)=6 10.5 10.6 More Easy Examples The Fibonacci Series Write down recursive definitions for: i+n (i integer, n natural) using only s(i) ) = i+1. a n (a real, n natural) using only addition a n (a real, n natural) using only multiplication! 0#i"n a i (for an arbitrary series of numbers {a{ i }) # 0#i"n a i (for an arbitrary series of numbers {a{ i }) $ 0#i"n S i (for an arbitrary series of sets {S{ i }) The Fibonacci series f n%0 is a famous series defined by: f 0 :" 0, f 1 :" 1, f n%2 :" f n!1 + f n!2 0 1 1 2 3 5 8 13 Leonardo Fibonacci 1170-1250 10.7 10.8

Inductive Proof about Fib. series A lower bound on Fibonacci series Theorem: f n < 2 n. Implicitly for all n#n Proof: By induction. Base cases: f 0 = 0 < 2 0 Note use of = 1 f 1 = 1 < 2 1 base cases of = 2 Inductive step: Use 2 nd principle of induction (strong induction). Assume $k<n, f k < 2 k. Then f n = f n!1 + f n!2 is < 2 n!1 + 2 n!2 < 2 n!1 + 2 n!1 = 2 n. ( recursive def n. Theorem. For all integers n % 3, f n > $ n!2, where $ = (1+5 1/2 )/2 ' 1.61803. Proof. (Using strong induction.) Let P(n) ) = (f( n > $ n!2 ). Base cases: For n=3, note that $ < 2 = f 3. For n=4, $ 2 = (1+2 5 1/2 +5)/4 = (3+5 1/2 )/2 ' 2.61803 < 3 = f 4. Inductive step: For k%4, assume P(j) ) for 3#j#k, 3, prove P(k+1). Note $ 2 = $+1. Thus, $ k!1 = ($+1)( +1)$ k!3 = $ k!2 $ k!3. By inductive hypothesis, f k!1 > $ k!3 and f k > $ k!2. So, f k+1 = f k + f k!1 > $ k!2 + $ k!3 = $ k!1. Thus P(k+1). (!2 + 10.9 10.10 Lamé s Theorem Proof of Lamé s Theorem Theorem: $a,b#n, a%b>0, the number of steps in Euclid s algorithm to find gcd(a,b) ) is # 5k,, where k = %log 10 b&+1 is the number of decimal digits in b. Thus, Euclid s s algorithm is linear- time in the number of digits in b. Proof: Uses the Fibonacci sequence! See next 2 slides. Gabriel Lamé 1795-1870 10.11 Consider the sequence of division- algorithm equations used in Euclid s alg.: r 0 = r 1 q 1 + r 2 with 0 # r 2 < r 1 r 1 = r 2 q 2 + r 3 with 0 # r 3 < r 2 r n!2 = r n!1!1q n!1 + r n with 0 # r n < r n!1 r n!1 = r n q n + r n+1 with r n+1 = 0 (terminate) The number of divisions (iterations) is n. Where a = r 0, b = r 1, and gcd(a,b)=r n. Continued on next slide 10.12

Lamé Proof, continued Recursively Defined Sets Since r 0 % r 1 > r 2 > > r n, each quotient q i " %r i!1!1/r i & % 1. Since r n!1 = r n q n and r n!1 > r n, q n % 2. So we have the following relations between r and f: r n % 1 = f 2 r n!1 % 2r n % 2f 2 = f 3 r n!2 % r n!1 + r n % f 2 + f 3 = f 4 r 2 % r 3 + r 4 % f n!1 + f n!2 = f n b = r 1 % r 2 + r 3 % f n + f n!1 = f n+1. Thus, if n>2 divisions are used, then b % f n+1 > $ n!1. Thus, log 10 b > log 10 ($ n!1 ) = (n!1(!1)log 10 $ ' (n!1)0.208 > (n!1(!1)/5. If b has k decimal digits, then log 10 b < k,, so n!1 < 5k, 5, so n " 5k. An infinite set S may be defined recursively, by giving: A small finite set of base elements of S. A rule for constructing new elements of S from previously-established elements. Implicitly, S has no other elements but these. Example: Let 3#S, 3, and let x+y#s if x,y#s. What is S? 10.13 10.14 The Set of All Strings Other Easy String Examples Given an alphabet,,, the set, * of all strings over, can be recursively defined by: - #, * Book (- :",, the empty string) uses. w #, * ' x #, ) wx #, * Exercise: Prove that this definition is equivalent to our old one: " # : $ U n!n # n Give recursive definitions for: The concatenation of strings w 1 w 2. The length l(w) ) of a string w. Well-formed formulae of propositional logic involving T, F,, propositional variables, and operators in {, ', (, ), *}. Well-formed arithmetic formulae involving variables, numerals, and ops in {+,!, *, +}. 10.15 10.16

Rooted Trees Illustrating Rooted Tree Def n. Trees will be covered in CompSci 130. Briefly, a tree is a graph in which there is exactly one undirected path between each pair of nodes. An undirected graph can be represented as a set of unordered pairs (called arcs) ) of objects called nodes. Definition of the set of rooted trees: Any single node r is a rooted tree. If T 1,, T n are disjoint rooted trees with respective roots r 1,, r n, and r is a node not in any of the T i s, then another rooted tree is {{r,r 1 },,{,{r,r n }})T 1 ) ) T n. How rooted trees can be combined to form a new rooted tree r T 1 r 1 T 2 r 2 T n r n Draw some examples 10.17 10.18 Extended Binary Trees Full Binary Trees A special case of rooted trees. Recursive definition of EBTs: The empty set * is an extended binary tree. If T 1,T 2 are disjoint EBTs,, then e 1 )e 2 ) T 1 )T 2 is an EBT, where e 1 = * if T 1 = *,, and e 1 = {(r,r 1 )} if T 1 / * and has root r 1, and similarly for e 2. A special case of extended binary trees. Recursive definition of FBTs: A single node r is a full binary tree. Note this is different from the EBT base case. If T 1,T 2 are disjoint FBTs,, then e 1 )e 2 )T 1 )T 2, where e 1 = * if T 1 = *,, and e 1 = {(r,r 1 )} if T 1 / *and has root r 1, and similarly for e 2. Note this is the same as the EBT recursive case! Can simplify it to If T 1,T 2 are disjoint FBTs with roots r 1 and r 2, then {(r, r 1 ),(r,r 2 )}) T 1 )T 2 is an FBT. Draw some examples Draw some examples 10.19 10.20

Structural Induction Proving something about a recursively defined object using an inductive proof whose structure mirrors the object s definition. Example problem: Let 3#S, 3, and let x+y# S if x,y#s.. Show that S = {n#z{ + (3 n)} (the set of positive multiples of 3). Example continued Let 3#S, 3, and let x+y#s if x,y#s. Let A = {n#z + (3 n)}. Theorem: A=S. Proof: We show that A+S and S+A. To show A+S,, show [n#z[ + ' (3 n)] )]) n#s. Inductive proof. Let P(n) ) :": n#s.. Induction over positive multiples of 3. Base case: n=3, thus 3#S 3 by def n.. of S.. Inductive step: Given P(n), prove P(n+3). By inductive hyp., n#s,, and 3#S, 3, so by def n of S, n+3#s. To show S+A: : let n#s,, show n#a. Structural inductive proof. Let P(n): ):"n#a.. Two cases: n=3 (base case), which is in A,, or n=x+y (recursive step). We know x and y are positive, since neither rule generates negative numbers. So, x<n and y<n,, and so we know x and y are in A,, by strong inductive hypothesis. Since 3 x and 3 y,, we have 3 (x+y), thus x+y # A. 10.21 10.22