Algorithms
D.L. Kreher
Department of Mathematical Sciences
Michigan Technological University
Houghton, MI 49931 kreher@mtu.edu and
D.R. Stinson
Department of Combinatorics and Optimization
University of Waterloo
Waterloo ON, N2L 3G1 dstinson@uwaterloo.ca 1
Introduction
This paper describes a LATEX environment named pseudocode that can be used for describing algorithms in pseudocode form. This is the style used in our textbook Combinatorial Algorithms: Generation, Enumeration and
Search [2]. The style file pseudocode.sty is available for free downloading from the web page http://www.math.mtu.edu/~kreher/cages.html
This package is quite easy to use, and allows algorithms to be described in a LATEX document using a natural Pascal-like syntax. In the remaining sections of this note, we describe how to use the pseudocode environment and we present some examples. Readers familiar with LATEX (see [3]) should be able to easily customize the style file to include additional desired features.
The pseudocode environment requires the fancybox package by Timothy Van Zandt. This package is described in Section 10.1.3 of [1]. Other environments for describing algorithms include alg, algorithmic, newalg and program. These style files, as well fancybox, are all available from the
CTAN web site http://www.ctan.org/
1
2
The pseudocode Environment
Within the pseudocode environment, a number of commands for popular algorithmic constructs are available. In general, the commands provided can be nested to describe quite complex algorithms.
The pseudocode environment is invoked as follows:
\begin{pseudocode}{<Name>}{<Parameters>}
pseudocode constructs
\end{pseudocode}
The argument <Name> is the name of the algorithm, and <Parameters> is a list of parameters for the algorithm. For example, the commands
\begin{pseudocode}{CelsiusToFahrenheit}{c}
f \GETS {9c/5} + 32\\
\RETURN{f}
\end{pseudocode} produce the following output when included
References: [1] M. Goossens, F. Mittelbach and A. Samarin, The LATEXCompanion, Addison-Wesley, 1994. [2] D.L. Kreher and D.R. Stinson, Combinatorial Algorithms: Generation, Enumeration and Search, CRC Press, 1999. [3] L. Lamport, LATEX, A Document Preparation System, Addison-Wesley, 1994. 14