Correctness proof of iterative algorithm, Exercises of Algorithms and Programming

This document is an exercise sheet. You can find 2 exercises on how to prove the algorithm. In this part, you can exercise about iterative algorithm.

Typology: Exercises

2018/2019

Available from 09/04/2021

PiotrRush
PiotrRush ๐Ÿ‡ฎ๐Ÿ‡ฉ

2 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
HOW TO PROVE THAT THESE ALGORITHMS ARE
CORRECT?
No. 1 function fib(n)
comment Return Fn
if n = 0 then return (0) else
a : = 0; b := 1; i :=2
while i < n do
c := a+b; a := b; b ;=c; i := i + 1
return(b)
No. 2 Proof for all n โˆˆ N, if 1 + x > 0, so (1 + x)n > 1 + nx
ANSWER No. 1
Recall on mathematical induction :
Claim for all n โˆˆ N,
1 + 2 + โ€ฆ + n = ๐‘›(๐‘›+1)
2
When using induction to prove that some statement concerning the positive integer is true, the
following terminology is used :
1. The induction base is the proof that the statement is true fot n = 1 (or another initial
value)
2. The induction hypothesis is the assumption that the statement is true for an arbitrary n
> 1 (or another initial value)
3. The induction step is the proof that if the statement is true for n, it must be also true
for n + 1
Then
Induction base : for n = 1
pf2

Partial preview of the text

Download Correctness proof of iterative algorithm and more Exercises Algorithms and Programming in PDF only on Docsity!

HOW TO PROVE THAT THESE ALGORITHMS ARE

CORRECT?

No. 1 function fib(n)

comment Return Fn

if n = 0 then return (0) else

a : = 0; b := 1; i :=

while i < n do

c := a+b; a := b; b ;=c; i := i + 1

return (b)

No. 2 Proof for all n โˆˆ N, if 1 + x > 0, so (1 + x)n^ > 1 + nx

ANSWER No. 1 Recall on mathematical induction : Claim for all n โˆˆ N, 1 + 2 + โ€ฆ + n = ๐‘›(๐‘›+ 1 ) 2 When using induction to prove that some statement concerning the positive integer is true, the following terminology is used :

  1. The induction base is the proof that the statement is true fot n = 1 (or another initial value)
  2. The induction hypothesis is the assumption that the statement is true for an arbitrary n

    1 (or another initial value)

  3. The induction step is the proof that if the statement is true for n, it must be also true for n + 1 Then Induction base : for n = 1

1 ( 1 + 1 ) 2 (True) Induction hypothesis : Assume, for an arbitrary positive integer n, that 1 + 2 + โ€ฆ + n = ๐‘›(๐‘›+ 1 ) 2 Induction step : We need to prove that 1 + 2 + โ€ฆ + n + (n + 1) = (๐‘›+ 1 )(๐‘›+ 2 ) 2 To that end , = ๐‘›(๐‘›+ 1 ) 2 + (n + 1) = ๐‘›^2 +๐‘› 2 + (n + 1) = ๐‘›^2 + 3 ๐‘›+ 2 2 = (๐ง+๐Ÿ)(๐’+๐Ÿ) ๐Ÿ (proved) ANSWER No. 2 Claim for all n โˆˆ N, Induction base : for n = 1 (1 + x)^1 > 1 + 1.x (True) Induction hypothesis : Assume, for an arbitrary positive integer n, that (1 + x)n+1^ > 1 + (n + 1)x Induction step : We need to prove that (1 + x)n+1^ > 1 + (n + 1)x (1 + x)n+1^ > (1 + x)n^ (1 + x)^1 (1 + x)n+1^ > (1 + x) (1 + nx) (1 + x)n+1^ > 1 + (n + 1)x + nx^2 nx^2 must be > 0, then it can be excluded (1 + x)n+1^ > 1 + (n + 1)x (proved)