1-twoup - The Selection Problem Given an array of numbers,...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The Selection Problem Given an array of numbers, we wish to find the k th smallest. • What if k is larger than n ? • Can the algorithm change the array? • If the elements are not all distinct, what exactly do we mean by the “ k th smallest”? To answer these and possibly other questions, we need a formal specification . 1 Algorithm Specifications An algorithm specification consists of three parts: • a precondition : a statement of the assumptions we make about the input to the algorithm and the environment in which it will be executed; • a postcondition : a statement of the required result of executing the algorithm, assuming the precondition is satisfied; and • a function header giving a name and parameter list. We say that an algorithm meets its specification if the postcondition is satisfied whenever the precondition is satisfied. 2 Specification for the Selection Problem Precondition: A [1 ..n ] is an array of Number s, 1 ≤ k ≤ n , k and n are Nat s....
View Full Document

This note was uploaded on 09/06/2009 for the course CIS 11274 taught by Professor Howell during the Spring '09 term at Kansas State University.

Page1 / 4

1-twoup - The Selection Problem Given an array of numbers,...

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

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