CSCB36H3 Study Guide - Quiz Guide: Postcondition, Precondition, Loop Invariant
Document Summary
Do not begin until you are told to do so. In the meantime, put your name on this cover page and read the rest of this page. There are 3 pages and each is numbered at the bottom. Use the backs of pages for rough work; they will not be graded. If you write in pencil or erasable pen, or if your quiz shows any evidence that work has been erased, then you forfeit the right to have your quiz re-graded. 21: [1 mark] print your name and student number here, [10 marks total] consider the following program. Precondition: a is nonempty list of integers. (it also works when a is empty, but that makes the question harder. ) Postcondition: the elements of a are rearranged in sorted (nondecreasing) order. Sort(a) k = 0 while k < len(a) 1: j = indexmin(a, k,len(a)) see question 2 for speci cation of indexmin. A[k], a[j] = a[j], a[k] k = k + 1.