Book contents
- Frontmatter
- Contents
- Preface
- Introduction
- A Algorithms
- Introduction to Part A
- 1 Specifying Algorithms
- 2 Verifying Algorithms: Basic Techniques
- 3 Verifying Algorithms: Some Examples
- 4 Additional Verification Techniques
- B Data Representations
- C Language Recognizers
- D Unimplementable Specifications
- Appendices
- Index
1 - Specifying Algorithms
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface
- Introduction
- A Algorithms
- Introduction to Part A
- 1 Specifying Algorithms
- 2 Verifying Algorithms: Basic Techniques
- 3 Verifying Algorithms: Some Examples
- 4 Additional Verification Techniques
- B Data Representations
- C Language Recognizers
- D Unimplementable Specifications
- Appendices
- Index
Summary
Case Study: Searching an Array
Professor Higgins wants his programmer, Eliza Doolittle, to write a code fragment that is to test for the presence or absence of a value x in an array A. Here is the intended application: A is to contain the student numbers of all the students currently enrolled in his course on computational metaphysics, and x might be the student number of a student who is trying to verify that he or she is properly registered.
Exercise 1.1 Before reading on, pretend that you are Eliza Doolittle and try to write the desired code. Also, try to write an application program that uses the code.
As you will quickly discover if you try to write the desired code, or to write a program to use it, the preceding paragraph is an inadequate specification. Here are some of the questions that must be answered before (or during) the development of the desired code or any associated applications.
What is the range of allowed subscript values for A, and what segment of the array should be searched?
What is the type of variable x (also, presumably, the component type of the array), and how should values of this type be compared?
How should the result be recorded?
Is the array segment sorted in, say, ascending order, to allow use of a more efficient search method?
[…]
- Type
- Chapter
- Information
- Specifying SoftwareA Hands-On Introduction, pp. 15 - 30Publisher: Cambridge University PressPrint publication year: 2002