Information Technology Reference
In-Depth Information
Notation
Mathematical notation is preferable to programming notation for presentation of
algorithms. Use “ x i ” rather than “ x[i] ”, for example. Don't use “ * ”or“ x ”to
denote multiplication; most word processors provide a multiplication symbol such
as “
”, and in any case multiplication is often implicit.
Likewise, avoid using constructs from specific programming languages. For
example, expressions such as == , a=b=0 , a++ , and for (i=0; i<n; i++) may
have little meaning, or even the wrong meaning, to readers who are unfamiliar with C.
Block-bounding statements such as begin and end are usually unnecessary; nest-
ing can be shown by indentation or by the numbering style, as in the examples in
Figs. 10.1 and 10.2 .
Mathematics provides numerous handy conventions and symbols that can be used
in description of algorithms, including set notation, subscripts and superscripts, and
symbols such as
×
”or“
·
, , and . But remember that such notation has a widely
understood formal meaning that should not be abused. Also, good programming style
does not necessarily imply good style for description of algorithms. For example,
take care with variable names of more than one character—don't use “ pq ” if it might
be interpreted as “ p
and
q ”.
It was once common to include the text of a program in a paper, in addition to a
description of the algorithm it embodies. Inclusion of the code was valuable because,
for short programs at least, it was the simplest way for readers to obtain the code.
However, this practice is now extremely rare.
×
Environment of Algorithms
The steps that comprise an algorithm are only part of its description. The other part is
its environment: the data structures on which it operates, input and output data types,
and, in some cases, factors such as properties of the underlying operating system
and hardware. If the environment of an algorithm is not described, the algorithm is
likely to be difficult to understand. For example, a presentation of a list-processing
algorithm should include descriptions of the list type, the input, and the possible
outputs. If the list is stored on secondary storage and speed is being analyzed, it
might also be appropriate to describe assumed disk characteristics. For algorithms in
which there are hardware considerations, such as memory size or disk throughput,
for the environment to seem realistic any assumptions about the hardware should
reflect current technology or likely improvements in the near future.
Specify the types of all variables, other than trivial items such as counters; describe
expected input and output, including assumptions about the correctness of the input;
state any limitations of the algorithm; and discuss possible errors that are not explicitly
captured by the algorithm. Most importantly, say what the algorithm does.
 
Search WWH ::




Custom Search