This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: then the loop will terminate. PreCondition: x,y ∈ Z ,z ∈ N . while ( x 6 = y and z ≥ 0) { if ( x > y ) { x = x  z; } else { y := yz ; } z = z1; } PostCondition: True. 3. Consider an array A [1 ..N ] with integer elements. The following algorithm recursively ﬁnds and returns the smallest element in the array. MIN ( A,f,l ) if ( f = l ) { return A[f] } m = ( f + l ) div 2 a = MIN ( A,f,m ) b = MIN ( A,m + 1 ,l ) if ( a < b ) { return a } else { return b } 1 (a) Write down the precondition and the postcondition for the above algorithm (Hint: your postcondition should include the fact that the return value is the smallest element of array A ). (b) Prove that the algorithm is correct (do not forget about termination). 2...
View
Full
Document
This note was uploaded on 04/11/2010 for the course CSC CSC236 taught by Professor Farzanazadeh during the Spring '10 term at University of Toronto Toronto.
 Spring '10
 FarzanAzadeh

Click to edit the document details