Docsity

Recursion and Recursive Definitions: Sets, Strings, Sequences, Functions, and Algorithms, Study notes of Number Theory

Partial preview of the text

Download Recursion and Recursive Definitions: Sets, Strings, Sequences, Functions, and Algorithms and more Study notes Number Theory in PDF only on Docsity!

Recursion

Zeph Grunschlag

Agenda

Recursion and Induction

Recursive Definitions

 Sets  Strings

Recursive Algorithms

Recursive Definitions

and Induction

Recursive definition and inductive proofs are complement each other: a recursive definition usually gives rise to natural proofs involving the recursively defined sequence.

This is follows from the format of a recursive definition as consisting of two parts:

  1. Initialization – analogous to induction base cases
  2. Recursion – analogous to induction step

In both induction and recursion, the domino analogy is useful.

Recursive Functions

It is possible to think of any function with domain

N as a sequence of numbers, and vice-versa.

Simply set: fn =f (n)

For example, our Fibonacci sequence becomes

the Fibonacci function as follows:

f (0) = 0, f (1) = 1, f (2) = 1, f (3) = 2,…

Such functions can then be defined recursively by

using recursive sequence definition. EG:

INITIALIZATION: f (0) = 0, f (1) = 1

RECURSION: f (n)=f (n -1)+f (n -2), for n > 1.

Recursive Functions

Factorial

A:INITIALIZATION: 0!= 1

RECURSION: n != n · (n -1)!

To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case.

EG: 5! =

Recursive Functions

Factorial

A:INITIALIZATION: 0!= 1

RECURSION: n != n · (n -1)!

To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case.

EG: 5! = 5 · 4!

recursion

Recursive Functions

Factorial

A:INITIALIZATION: 0!= 1

RECURSION: n != n · (n -1)!

To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case.

EG: 5! = 5 · 4! = 5 · 4 · 3! = 5 · 4 · 3 · 2!

recursion

Recursive Functions

Factorial

A:INITIALIZATION: 0!= 1

RECURSION: n != n · (n -1)!

To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case.

EG: 5! = 5 · 4! = 5 · 4 · 3! = 5 · 4 · 3 · 2!

recursion

L16 13

Recursive Functions

Factorial

A:INITIALIZATION: 0!= 1

RECURSION: n != n · (n -1)!

To compute the value of a recursive function, e.g. 5!, one plugs into the recursive definition obtaining expressions involving lower and lower values of the function, until arriving at the base case.

EG: 5! = 5 · 4! = 5 · 4 · 3! = 5 · 4 · 3 · 2!

recursion

initializatio

L16 14

Recursive Functions

n choose k

The Binomial coefficients arise in several

applications:

1) Combinatorics/Probability (n choose k):

C (n,k) = the number of different groups

of size k from an initial group of size n

2) Algebra:

C (n,k) = coefficient of k th^ term in the

expansion of the n th^ binomial power

(x + y )^ n

Commonly used notation:

k

n

C ( n , k )

n choose k

and Pascal’s Triangle

n choose k

and Pascal’s Triangle

n choose k

and Pascal’s Triangle

n choose k

and Pascal’s Triangle