Mad111 Chap 4
Mad111 Chap 4
Mad111 Chap 4
Department of Mathematics
The FPT university
Topics covered:
Topics covered:
Topics covered:
Topics covered:
Topics covered:
Topics covered:
Proof by Induction:
Proof by Induction:
Proof by Induction:
Proof by Induction:
Proof by Induction:
Proof by Induction:
F0 = 0, F1 = 1,
F0 = 0, F1 = 1, and
F0 = 0, F1 = 1, and
Fn = Fn−1 + Fn−2 for n = 2, 3, . . ..
F0 = 0, F1 = 1, and
Fn = Fn−1 + Fn−2 for n = 2, 3, . . ..
F0 = 0, F1 = 1, and
Fn = Fn−1 + Fn−2 for n = 2, 3, . . ..
(a) xn = 7 ∗ 5n+1
(a) xn = 7 ∗ 5n+1
(b) xn = n!
(a) xn = 7 ∗ 5n+1
(b) xn = n!
(c) xn = (−1)n
(a) xn = 7 ∗ 5n+1
(b) xn = n!
(c) xn = (−1)n
(d) xn = 2n − 6
(a) xn = 7 ∗ 5n+1
(b) xn = n!
(c) xn = (−1)n
(d) xn = 2n − 6
Basic step: 3 ∈ S
Basic step: 3 ∈ S
Recursive step: If x, y ∈ S then x + y ∈ S
Basic step: 3 ∈ S
Recursive step: If x, y ∈ S then x + y ∈ S
Example 2.
Basic step: 3 ∈ S
Recursive step: If x, y ∈ S then x + y ∈ S
Example 2.
(a) Give a recursive definition for the set of positive integers that are not
divisible by 3
Basic step: 3 ∈ S
Recursive step: If x, y ∈ S then x + y ∈ S
Example 2.
(a) Give a recursive definition for the set of positive integers that are not
divisible by 3
(b) Give a recursive definition for the set of integers that are not divisible
by 3
Basic step: 3 ∈ S
Recursive step: If x, y ∈ S then x + y ∈ S
Example 2.
(a) Give a recursive definition for the set of positive integers that are not
divisible by 3
(b) Give a recursive definition for the set of integers that are not divisible
by 3
Basic step: Prove that P is true for elements of S defined in the basic
step.
Basic step: Prove that P is true for elements of S defined in the basic
step.
Recursive step: Show that if the property P is true for the elements
used to construct new elements in the recursive step of the definition
of S, then the property P is also true for these new elements.
Example 2. Let T be a full binary tree with the number of vertices n(T )
and the height h(T ). Prove that n(T ) ≤ 2h(T )+1 − 1.
Example 2. Let T be a full binary tree with the number of vertices n(T )
and the height h(T ). Prove that n(T ) ≤ 2h(T )+1 − 1.
Example.
Example.
Example.
a0,0 = 0, and
Example.
a0,0 = 0,
and
am−1,n + 1 if n = 0 v m > 0,
am,n =
am,n−1 + n if n > 0
Example.
a0,0 = 0,
and
am−1,n + 1 if n = 0 v m > 0,
am,n =
am,n−1 + n if n > 0
Procedure mergesort (L = a1 , a2 , . . . , an )
if n > 1 then
m := bn/2c
L1 = a1 , a2 , . . . , am
L2 = am+1 , am+2 , . . . , an
L := merge(mergesort(L1 ), mergersort(L2 ))
Print (L)
Procedure mergesort (L = a1 , a2 , . . . , an )
if n > 1 then
m := bn/2c
L1 = a1 , a2 , . . . , am
L2 = am+1 , am+2 , . . . , an
L := merge(mergesort(L1 ), mergersort(L2 ))
Print (L)
Theorem
Procedure mergesort (L = a1 , a2 , . . . , an )
if n > 1 then
m := bn/2c
L1 = a1 , a2 , . . . , am
L2 = am+1 , am+2 , . . . , an
L := merge(mergesort(L1 ), mergersort(L2 ))
Print (L)
Theorem
The number of comparisons needed to merge sort a list of n elements is
O(n log n).
Prove that if the program terminates then the answer is correct (this
part is called partial correctness).
Prove that if the program terminates then the answer is correct (this
part is called partial correctness).
Show that the program always terminates.
y:=2
z:=x+y
is
y:=2
z:=x+y
is
y:=2
z:=x+y
is
if condition then
S
if condition then
S
if condition then
S
(p∧ condition){S}q
(p ∧ ¬ condition) → q
if condition then
S1
else
S2
if condition then
S1
else
S2
if condition then
S1
else
S2
(p∧ condition){S1 }q
(p ∧ ¬ condition) {S2 }q
while condition
S
while condition
S
while condition
S
while condition
S
If a loop invariant p is chosen then the rule of inference for this program
segment is:
while condition
S
If a loop invariant p is chosen then the rule of inference for this program
segment is:
(p∧ condition){S}p
while condition
S
If a loop invariant p is chosen then the rule of inference for this program
segment is:
(p∧ condition){S}p
i := 1
factorial := 1
while i < n
begin
i := i + 1
factorial := factorial ∗ i
end
i := 1
factorial := 1
while i < n
begin
i := i + 1
factorial := factorial ∗ i
end
i := 1
factorial := 1
while i < n
begin
i := i + 1
factorial := factorial ∗ i
end
i := 1
factorial := 1
while i < n
begin
i := i + 1
factorial := factorial ∗ i
end
i := 1
factorial := 1
while i < n
begin
i := i + 1
factorial := factorial ∗ i
end
power := 1
i := 1
while i ≤ n
begin
power := power ∗ x
i := i + 1
end