sort - EXAMPLE Vector Y = SORT(Vector X) pre: true post:...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
EXAMPLE • Vector Y = SORT(Vector X) pre: true post: ORDERED(Y) PERMUTATION(X,Y)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sorting Routine • Provide an English-language statement describing the expected behavior of a routine SORT(X,Y) where X is an input vector of integers and Y is an output vector • Now express the same behavior in predicate calculus
Background image of page 2
Sorting (English) • Preconditions: for SORT any input vector X qualifies. Thus, SORT is always able to run. This precondition is designated as true • Postconditions – Y must be the same length as X – The output vector Y must be ordered – The contents of Y must be the "same as" the contents of X • Everything in X must be in Y • Everything in Y must have come from X • The number of occurrences of each item in Y must be the same as its number of occurrences in X
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sorting - Predicate Calculus • Y must be the same length as X – X and Y are vectors – Vectors (as a datatype) have properties one of which is their length – |X| == |Y| or X.length() == Y.length() or #X == #Y
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 16

sort - EXAMPLE Vector Y = SORT(Vector X) pre: true post:...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online