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

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

EXAMPLE • Vector Y = SORT(Vector X) pre: true post: ORDERED(Y) PERMUTATION(X,Y)

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

View Full Document
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
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

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

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
Ask a homework question - tutors are online