You are on page 1of 69

Functions

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen

Chapter 4 An Khuong, Le Hong


Trang

Functions
Discrete Structures for Computing on August 31, 2021
Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion

Huynh Tuong Nguyen, Tran Tuan Anh, Nguyen An Khuong, Le


Hong Trang
Faculty of Computer Science and Engineering
University of Technology - VNUHCM
trtanh@hcmut.edu.vn - htnguyen@hcmut.edu.vn
4.1
Functions
Contents
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

1 Functions

Contents

2 One-to-one and Onto Functions Functions

One-to-one and Onto


Functions

Sequences and
Summation
3 Sequences and Summation Recursion

4 Recursion

4.2
Functions
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang
Course learning outcomes

L.O.1 Understanding of logic and discrete structures


L.O.1.1 – Describe definition of propositional and predicate logic
L.O.1.2 – Define basic discrete structures: set, mapping, graphs

Contents
L.O.2 Represent and model practical problems with discrete structures
L.O.2.1 – Logically describe some problems arising in Computing Functions

L.O.2.2 – Use proving methods: direct, contrapositive, induction One-to-one and Onto
Functions
L.O.2.3 – Explain problem modeling using discrete structures
Sequences and
Summation
L.O.3 Understanding of basic probability and random variables
Recursion
L.O.3.1 – Define basic probability theory
L.O.3.2 – Explain discrete random variables

L.O.4 Compute quantities of discrete structures and probabilities


L.O.4.1 – Operate (compute/ optimize) on discrete structures
L.O.4.2 – Compute probabilities of various events, conditional
ones, Bayes theorem

4.3
Functions
Introduction
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

• Each student is assigned a grade from set


{0, 0.1, 0.2, 0.3, . . . , 9.9, 10.0} at the end of semester Contents

• Function is extremely important in mathematics and Functions

computer science One-to-one and Onto


Functions
• linear, polynomial, exponential, logarithmic,... Sequences and
Summation
• Don’t worry! For discrete mathematics, we need to Recursion
understand functions at a basic set theoretic level

4.4
Functions
Function
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Definition An Khuong, Le Hong
Trang
Let A and B be nonempty sets. A function f from A to B is an
assignment of exactly one element of B to each element of A.
• f :A→B
• A: domain (miền xác định) of f
• B: codomain (miền giá trị) of f Contents

• For each a ∈ A, if f (a) = b Functions

• b is an image (ảnh) of a One-to-one and Onto


Functions
• a is pre-image (nghịch ảnh) of f (a)
Sequences and
• Range of f is the set of all images of elements of A Summation

Recursion
• f maps (ánh xạ) A to B

f
a b = f (a)

A B
f
4.5
Functions
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion

• Example:
• y is an image of d
• c is a pre-image of z

4.6
Functions
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Example
What are domain, codomain, and range of the function that
assigns grades to students includes: student A: 5, B: 3.5, C: 9, D:
5.2, E: 4.9? Contents

Functions
Example One-to-one and Onto
Functions
Let f : Z → Z assign the the square of an integer to this integer. Sequences and
What is f (x)? Domain, codomain, range of f ? Summation

Recursion
• f (x) = x2
• Domain: set of all integers
• Codomain: Set of all integers
• Range of f : {0, 1, 4, 9, . . .}

4.7
Functions
Add and multiply real-valued functions
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Definition
Let f1 and f2 be functions from A to R. Then f1 + f2 and f1 f2
are also functions from A to R defined by
(f1 + f2 )(x) = f1 (x) + f2 (x) Contents

(f1 f2 )(x) = f1 (x)f2 (x) Functions

One-to-one and Onto


Functions

Sequences and
Example Summation

Recursion
Let f1 (x) = x2 and f2 (x) = x − x2 . What are the functions
f1 + f2 and f1 f2 ?
(f1 + f2 )(x) = f1 (x) + f2 (x) = x2 + x − x2 = x
(f1 f2 )(x) = f1 (x)f2 (x) = x2 (x − x2 ) = x3 − x4

4.8
Functions
Image of a subset
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Definition
Let f : A → B and S ⊆ A. The image of S:

f (S) = {f (s) | s ∈ S} Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion

f ({a, b, c, d}) = {x, y, z}

4.9
Functions
One-to-one
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Definition
A function f is one-to-one or injective (đơn ánh) if and only if

∀a∀b (f (a) = f (b) → a = b) Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation
• Is f : Z → Z, f (x) = x + 1
Recursion
one-to-one?
• Is f : Z → Z, f (x) = x2
one-to-one?

4.10
Functions
Onto
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Definition
f : A → B is onto or surjective (toàn ánh) if and only if

∀b ∈ B, ∃a ∈ A : f (a) = b Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation
• Is f : Z → Z, f (x) = x + 1
Recursion
onto?
• Is f : Z → Z, f (x) = x2
onto?

4.11
Functions
One-to-one and onto (bijection)
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Definition
f : A → B is bijective (one-to-one correspondence) (song ánh) if
and only if f is injective and surjective Contents

Functions

One-to-one and Onto


Functions
• Let f be the function from
Sequences and
{a, bc, d} to {1, 2, 3, 4} with Summation

f (a) = 4, f (b) = 2, Recursion

f (c) = 1, f (d) = 3. Is f a
bijection?

4.12
Functions
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion

4.13
Functions
Inverse function (Hàm ngược)
Huynh Tuong Nguyen,
Definition Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang
Let f : A → B be a bijection then the inverse of f is the function
f − : B → A defined by

if f (a) = b then f − (b) = a

A one-to-one correspondence is call invertible (khả nghịch) Contents


because we can define the inverse of this function. Functions

One-to-one and Onto


Functions
f (a) Sequences and
Summation

Recursion

−1
a = f −1 (b) f (b) b = f (a)

A f B

f −1
4.14
Functions
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Example
A = {a, b, c} and B = {1, 2, 3} with

f (a) = 2 f (b) = 3 f (c) = 1 Contents

Functions

f is invertible and its inverse is One-to-one and Onto


Functions

Sequences and
f −1 (1) = c f −1 (2) = a f −1 (3) = b Summation

Recursion

Example
Let f : R → R with f (x) = x2 . If f invertible?

4.15
Functions
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

f :R→R
Contents

Functions
f (x) = 2x + 1
One-to-one and Onto
Functions

Sequences and
f −1 : R → R Summation

Recursion

x−1
f −1 (x) =
2

4.16
Functions
Function Composition
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Definition
Given a pair of functions g : A → B and f : B → C. Then the Contents
composition (hợp thành) of f and g, denoted f ◦ g is defined by Functions

One-to-one and Onto


Functions
f ◦g :A→C
Sequences and
Summation
f ◦ g(a) = f (g(a)) Recursion

4.17
Functions
Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion

4.18
Functions
Graphs of Functions
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang
Example
The graph of f (x) = x2 from Z to Z.

(−3, 9) (3, 9)
Contents

Functions

(−2, 4) (2, 4) One-to-one and Onto


Functions

Sequences and
Summation
(−1, 1) (1, 1)
Recursion

(0, 0)

Definition
Let f be a function from the set A to the set B. The graph of the
function f is the set of ordered pairs {(a, b) | a ∈ A and f (a) = b}.

4.19
Functions
Important Functions
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Definition An Khuong, Le Hong
Trang
Floor function (hàm sàn) of x (bxc): the largest integer ≤ x
b 12 c = 0, b3.1c = 3, b7c = 7
Ceiling function (hàm trần) of x (dxe): the smallest integer ≥ x
d 12 e = 1, d3.1e = 4, d7e = 7

Contents

Functions
Bảng: Properties (n is an integer, x is a real number)
One-to-one and Onto
Functions
(1a) bxc = n iff n≤x<n+1 Sequences and
Summation
(1b) dxe = n iff n−1<x≤n
Recursion
(1c) bxc = n iff x−1<n≤x
(1d) dxe = n iff x≤n<x+1
(2) x − 1 < bxc ≤ dxe < x + 1
(3a) b−xc = −dxe
(3b) d−xe = −bxc
(4a) bx + nc = bxc + n
(4b) dx + ne = dxe + n
4.20
Functions
Sequences
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang
What are the rule of these sequences (dãy )?
Example
1, 3, 5, 7, 9, . . . an = 2n − 1
Arithmetic sequence (cấp số cộng )
Contents

Functions

One-to-one and Onto


Example Functions

1, 12 , 14 , 81 , 16
1 1 Sequences and
,... an = 2n−1 Summation

Geometric sequence (cấp số nhân) Recursion

Example
{an } 5, 11, 17, 23, 29, 35, 41, 47, . . . an = 6n − 1
{bn } 1, 7, 25, 79, 241, 727, 2185, . . . bn = 3n − 2

4.21
Functions
Recurrence Relations
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Example Trang

{an } 5, 11, 17, 23, 29, 35, 41, 47, . . .


an = an−1 + 6 for n = 2, 3, 4, . . . and a1 = 5
Recurrence relations: công thức truy hồi

Contents
Definition (Fibonacci Sequence) Functions

One-to-one and Onto


Initial condition: f0 = 0 and f1 = 1 Functions

fn = fn−1 + fn−2 for n = 2, 3, 4, . . . Sequences and


Summation

Recursion
Example
Find the Fibonacci numbers f2 , f3 , f4 , f5 and f6
f2 = f1 + f0 =1+0=1
f3 = f2 + f1 =1+1=2
f4 = f3 + f2 =2+1=3
f5 = f4 + f3 =3+2=5
f6 = f5 + f4 =5+3=8
4.22
Functions

Exercise (1) Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Initial deposit: $10,000 Trang
Interest: 11%/year, compounded annually (lãi suất kép)
After 30 years, how much do you have in your account?

Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion

4.23
Functions

Exercise (1) Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Initial deposit: $10,000 Trang
Interest: 11%/year, compounded annually (lãi suất kép)
After 30 years, how much do you have in your account?
Solution:
Let Pn be the amount in the account after n years. The sequence
Contents
{Pn } satisfies the recurrence relation
Functions
Pn = Pn−1 + 0.11Pn−1 = (1.11)Pn−1 .
One-to-one and Onto
The initial condition is P0 = 10, 000 Functions

Sequences and
Summation

Recursion

4.23
Functions

Exercise (1) Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Initial deposit: $10,000 Trang
Interest: 11%/year, compounded annually (lãi suất kép)
After 30 years, how much do you have in your account?
Solution:
Let Pn be the amount in the account after n years. The sequence
Contents
{Pn } satisfies the recurrence relation
Functions
Pn = Pn−1 + 0.11Pn−1 = (1.11)Pn−1 .
One-to-one and Onto
The initial condition is P0 = 10, 000 Functions

Sequences and
Step 1. Solve the recurrence relation (iteration technique) Summation

P1 = (1.11)P0 Recursion

P2 = (1.11)P1 = (1.11)2 P0
P3 = (1.11)P2 = (1.11)3 P0
..
.
Pn = (1.11)Pn−1 = (1.11)n P0 .

4.23
Functions

Exercise (1) Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Initial deposit: $10,000 Trang
Interest: 11%/year, compounded annually (lãi suất kép)
After 30 years, how much do you have in your account?
Solution:
Let Pn be the amount in the account after n years. The sequence
Contents
{Pn } satisfies the recurrence relation
Functions
Pn = Pn−1 + 0.11Pn−1 = (1.11)Pn−1 .
One-to-one and Onto
The initial condition is P0 = 10, 000 Functions

Sequences and
Step 1. Solve the recurrence relation (iteration technique) Summation

P1 = (1.11)P0 Recursion

P2 = (1.11)P1 = (1.11)2 P0
P3 = (1.11)P2 = (1.11)3 P0
..
.
Pn = (1.11)Pn−1 = (1.11)n P0 .
Step 2. Calculate
P30 = (1.11)30 10, 000 = $228, 922.97.
4.23
Functions

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
Exercise (2) An Khuong, Le Hong
Trang
What is the 2012th number in the sequence {xn }: 1, 2, 2, 3, 3, 3,
4, 4, 4, 4, 5, 5, 5, 5, 5, 6,. . .

Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion

4.24
Functions

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
Exercise (2) An Khuong, Le Hong
Trang
What is the 2012th number in the sequence {xn }: 1, 2, 2, 3, 3, 3,
4, 4, 4, 4, 5, 5, 5, 5, 5, 6,. . .
Solution:
In this sequence, integer 1 appears once, the integer 2 appears
twice, the integer 3 appears three times, and so on. Therefore Contents
integer n appears n times in the sequence. Functions

One-to-one and Onto


We can prove that (try it!) Functions
n
X n(n + 1) Sequences and
i = 1 + 2 + 3 + ... + n = Summation

i=1
2 Recursion

and can easily calculate that


X62
i = 1953
i=1
so the next 63 numbers (until 2016) is 63.
Therefore, 2012th number in the sequence is 63.

4.24
Functions

Theorem Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
If a and r are real numbers and r 6= 0, then An Khuong, Le Hong
Trang

n  ar n+1 −a
X if r 6= 1
arj = r−1
j=0
(n + 1)a if r = 1.

Contents
Chứng minh.
Functions
Pn
Let Sn = j=0 arj . One-to-one and Onto
Functions
Pn Sequences and
rSn = r j=0 arj Summation
Pn
= j=0 arj+1 Recursion
Pn+1
=  k=1 ark 
Pn k
= k=0 ar + (arn+1 − a)
= Sn + (arn+1 − a)

ar n+1 −a
Solving for Sn shows that if r 6= 1, then Sn = r−1
Pn
If r = 1, then Sn = j=0 a = (n + 1)a

4.25
Functions
Recursion
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Definition (Recurrence Relation) An Khuong, Le Hong
Trang

An equation that recursively defines a sequence.

Definition (Recursion (đệ quy))


The act of defining an object (usually a function) in terms of that Contents
object itself. Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion

4.26
Functions
Recursive Algorithms
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Definition
An algorithm is called recursive if it solves a problem by reducing
it to an instance of the same problem with smaller input.

Contents
Example
Functions

Give a recursive algorithm for computing n!, where n is a One-to-one and Onto
Functions
nonnegative integer.
Sequences and
Summation

Solution. We base on the recursive definition of n!: Recursion

n! = n · (n − 1)! and 0! = 1.
procedure factorial (n: nonnegative integer)
if n = 0 then return 1
else return n· factorial (n - 1)
{output is n!}

4.27
Functions
Algorithms for Fibonacci Numbers
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Recursive Algorithm An Khuong, Le Hong
Trang
procedure fibonacci(n: nonnegative integer)
if n = 0 then return 0
else if n = 1 then return 1
else return fibonacci(n-1) + fibonacci(n-2)
{output is fibonacci(n)}
Contents

Functions
Iterative Algorithm
One-to-one and Onto
Functions
procedure iterative fibonacci(n: nonnegative integer)
Sequences and
if n = 0 then return 0 Summation

else Recursion

x := 0
y := 1
for i := 1 to n − 1
z := x + y
x := y
y := z
return y
{output is the nth Fibonacci number}
4.28
Functions
Tower of Hanoi
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

There is a tower in Hanoi that has three pegs mounted on a board


together with 64 gold disks of different sizes.
Initially, these disks are placed on the first peg in order of size,
with the largest on the borrom. Contents

Functions
The rules: One-to-one and Onto
Functions
1 Move one at a time from one peg to another Sequences and
Summation
2 A disk is never placed on top of a smaller disk
Recursion

Goals: all the disks on the third peg in order of size.

The myth says that the world will end when they finish the
puzzle.

4.29
Functions
Tower of Hanoi – 64 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

1
2
3
4
? Contents

Functions

One-to-one and Onto


Functions

Sequences and
5 Summation

Recursion
6

4.30
Functions
Tower of Hanoi – 1 Disc
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion
1

4.31
Functions
Tower of Hanoi – 1 Disc
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion
1

Moved disc from peg 1 to peg 3.

4.32
Functions
Tower of Hanoi – 1 Disc
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

OK Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion
1

4.33
Functions
Tower of Hanoi – 2 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
1 Summation

Recursion
2

4.34
Functions
Tower of Hanoi – 2 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion
2 1

Moved disc from peg 1 to peg 2.

4.35
Functions
Tower of Hanoi – 2 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion
1 2

Moved disc from peg 1 to peg 3.

4.36
Functions
Tower of Hanoi – 2 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
1 Summation

Recursion
2

Moved disc from peg 2 to peg 3.

4.37
Functions
Tower of Hanoi – 2 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

OK Contents

Functions

One-to-one and Onto


Functions

Sequences and
1 Summation

Recursion
2

4.38
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


1 Functions

Sequences and
2 Summation

Recursion
3

4.39
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
2 Summation

Recursion
3 1

Moved disc from peg 1 to peg 3.

4.40
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion
3 2 1

Moved disc from peg 1 to peg 2.

4.41
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
1 Summation

Recursion
3 2

Moved disc from peg 3 to peg 2.

4.42
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
1 Summation

Recursion
2 3

Moved disc from peg 1 to peg 3.

4.43
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
Summation

Recursion
1 2 3

Moved disc from peg 2 to peg 1.

4.44
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
2 Summation

Recursion
1 3

Moved disc from peg 2 to peg 3.

4.45
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


1 Functions

Sequences and
2 Summation

Recursion
3

Moved disc from peg 1 to peg 3.

4.46
Functions
Tower of Hanoi – 3 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

OK 1
Contents

Functions

One-to-one and Onto


Functions

Sequences and
2 Summation

Recursion
3

4.47
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions
1 One-to-one and Onto
2 Functions

Sequences and
3 Summation

Recursion
4

4.48
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


2 Functions

Sequences and
3 Summation

Recursion
4 1

Moved disc from peg 1 to peg 2.

4.49
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
3 Summation

Recursion
4 1 2

Moved disc from peg 1 to peg 3.

4.50
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
3 1 Summation

Recursion
4 2

Moved disc from peg 2 to peg 3.

4.51
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
1 Summation

Recursion
4 3 2

Moved disc from peg 1 to peg 2.

4.52
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
1 Summation

Recursion
4 3 2

Moved disc from peg 3 to peg 1.

4.53
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
1 2 Summation

Recursion
4 3

Moved disc from peg 3 to peg 2.

4.54
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


1 Functions

Sequences and
2 Summation

Recursion
4 3

Moved disc from peg 1 to peg 2.

4.55
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


1 Functions

Sequences and
2 Summation

Recursion
3 4

Moved disc from peg 1 to peg 3.

4.56
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
2 1 Summation

Recursion
3 4

Moved disc from peg 2 to peg 3.

4.57
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
1 Summation

Recursion
2 3 4

Moved disc from peg 2 to peg 1.

4.58
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
1 Summation

Recursion
2 3 4

Moved disc from peg 3 to peg 1.

4.59
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
1 3 Summation

Recursion
2 4

Moved disc from peg 2 to peg 3.

4.60
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


Functions

Sequences and
3 Summation

Recursion
2 1 4

Moved disc from peg 1 to peg 2.

4.61
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions

One-to-one and Onto


2 Functions

Sequences and
3 Summation

Recursion
1 4

Moved disc from peg 1 to peg 3.

4.62
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents

Functions
1 One-to-one and Onto
2 Functions

Sequences and
3 Summation

Recursion
4

Moved disc from peg 2 to peg 3.

4.63
Functions
Tower of Hanoi – 4 Discs
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

OK 1
2
Contents

Functions

One-to-one and Onto


Functions

Sequences and
3 Summation

Recursion
4

4.64
Functions
Tower of Hanoi
Huynh Tuong Nguyen,
Algorithm Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang
procedure hanoi(n, A, B, C)
if n = 1 then move the disk from A to C
else
call hanoi(n − 1, A, C, B)
move disk n from A to C
call hanoi(n − 1, B, A, C) Contents

Functions

One-to-one and Onto


Recurrence Relation Functions

Sequences and
 Summation
1 if n = 1
H(n) = Recursion
2H(n − 1) + 1 if n > 1.

Recurrence Solving
H(n) = 2n − 1
If one move takes 1 second, for n = 64

264 − 1 ≈ 2 × 1019 sec


≈ 500 billion years!.
4.65

You might also like