UMBC CS 201, Spring 02
Problem decomposition
The write/compile/test method
Small programs are written using the "write/compile/test" model.
- It may take several iterations of the model to produce a working
program.
- As programs get more complicated, testing and debugging alone may not
be enough to produce reliable code.
- Instead, we have to write programs in a manner that will help insure
that errors are caught or avoided.
Divide and Conquer
A central part of programming, then, is taking a large and complex
problem and decomposing it into smaller
problems that can more easily be solved.
- This is not a one step process -- we further decompose the sub
problems into sub-sub problems, etc.
- There are a number of general techniques and methodologies
that have been developed to address this problem in the context of
computer science.
-
A classic book on the topic of problem solving strategies is:
G. Polya, 1947. How To Solve It, Princeton University Press,
Princeton, NJ.
Useful Methods and techniques
- Top-down implementation
- Bottom-up implementation
- Program stubs
- Incremental program development
Some portions are adapted from Oh! Pascal third edition and notes by
Anthony Aaby, aabyan@wwc.edu.
Top Down Design and Programming
Top-Down Programming, or
Stepwise Refinement
- Useful as both a design and an implementation
methodology.
- begin with the top-level, user-invoked module and work
toward the modules that do not call any other modules.
- May proceed depth-first or breadth-first.
1
|
+------+------+
| | |
2 3 4
/ \ /|\ |
5 6 8 9 10 11
| |
12 13
- depth-first: 1 2 5 6 3 8 9 12 10 4 11 13
- breadth-first: 1 2 3 4 5 6 8 9 10 11 12 13
- Program stubs are used for the lowest, unimplemented
layer.
- Problem: will we be able to realize the lowest level modules?
- Advantage: design from the requirements to the details keeps
the requirements in focus.
Bottom Up Design and Implementation
- Start with the lowest level modules and work toward the top.
- Use a "test harness" to test and debug the results at any
given level.
- Problem: will we be able to integrate the final pieces to
satisfy the ultimate requirements?
- Advantage: we are always working with concrete, real data.
- Generally not as good as top-down design and implementation.
Program Stubs
- Stub programming is the implementation analogue of top-down
design and stepwise refinement and supports incremental program
development by allowing for error and improvement.
- A stub program is a stripped-down,
skeleton version of a final program. It doesn't implement details of
the algorithm or fulfill all the job requirements.
- It does contain, in a form that can be compiled and
run, rough versions of all subprograms and their parameter lists.
Incremental Program Development
As programs become more complex, changes have a tendency to introduce
unexpected effects.