This preview shows pages 1–3. 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: 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.
 Spring '09
 Howell

Click to edit the document details