User`s Guide - The MIT Press

User’s Guide
User’s Guide
LaTeX Template Guidance
1. The MIT Press LaTeX templates are available in three trim sizes at
http://mitpress.mit.edu/content/guidelines-authors-preparingmanuscript-files-tex. Please check with your editor on the correct
set of macros to download.
2. The template is designed using the MiKTeX 2.9 package. After
installing MiKTeX 2.9 (http://miktex.org/2.9/setup), all style files
will be automatically installed. The MIT Press template includes
additional macros.
3. Our templates can also be used on the Mac (see instructions below).
4. The MIT Press template is designed to support numbered references.
For more information on references, please see the Bibliography
section later in this document.
Compilation procedure for both MAC and PC users
For each trim size, a complete set of macros is provided for the PC and
the Mac:
Template-6x9-solution:
• Mac_Compilation
• PC_Compilation
Template-7x9-solution
• Mac_Compilation
• PC_Compilation
Template-8x9-solution
• Mac_Compilation
• PC_Compilation
1
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
User’s Guide
2
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
PC USERS
1. Install MiKTeX 2.9 and any LaTeX-compatible editor (such as WinEdt,
available at http://www.winedt.com).
2. Copy the supplied “PC_Compilation” folder to your PC.
3. Open the root files “Sample-6x9.tex” in WinEdt.
4. Start the compilation process using PDFLatex, available as a dropdown
choice in the WinEdt toolbar.
If you don’t have the WinEdt editor installed, run the following
command to compile:
pdflatex Sample-6x9 (root file name)
To view the output of the compiled file, run the following command:
start Sample-6x9.pdf (root file name with extension .pdf)
5. These instructions are the same for the other two templates:
a. Template-7x9-solution
b. Template-8x9-solution
MAC USERS
1. Install MacTeX and a LaTeX editor (such as TeXShop, available at http://
pages.uoregon.edu/koch/texshop/).
2. Copy the supplied “MAC_Compilation” folder to your machine.
3. Open the root file “Sample-6x9.tex” in TeXShop.
4. Start the compilation process using the LaTeX option.
5. These instructions are the same for the other two templates:
a. Template-7x9-solution
b. Template-8x9-solution
User’s Guide
Basic Class File
Option used in class file
1. timesfont
2. dblspace
Use \documentclass[timesfont,dblspace]{MITPress-diacriTech-7x9}
You can use “timesfont” if you want to switch from the default
Computer Modern
fonts to Times.
Important: If your manuscript is going to be printed for copyediting,
use the “dblspace” command to double-space the lines of text. This
command can be removed after copyediting is complete.
3
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
User’s Guide
4
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Front Matter
Use the command “\frontmatter” after “\begin{document}”
Half Title
\halftitle{Introduction to Algorithms}
Series page
\begin{seriespage}
\seriestitle{Series Title}
%for Series Title
\serieseditor{Clifford Stein}
%for Series Editor
\begin{seriesentry}
\item Series entry title
%for Series Entry Title
\seriesauthor{Ronald L. Rivest} %for Series Author
\item Series
entry title
sample-6x9
2014/5/27 12:42%for
PageSeries
ii #2 Entry Title
\seriesauthor{Ronald L. Rivest} %for Series Author
\end{seriesentry}
\end{seriespage}
Which produces:
Series Title
Clifford Stein
1 Series entry title
Ronald L. Rivest
2 Series entry title
Ronald L. Rivest
User’s Guide
5
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Book Title
\booktitle{Introduction to Algorithms}
Subtitle
\subtitle{Sub Title}
Edition
\edition{Third Edition}
Author/Editor
\edauthor{Thomas H. Cormen\\
Charles E. Leiserson\\
Ronald L. Rivest\\
Clifford Stein
}
sample-6x9 2014/5/27 12:42 Page iii
#3
Which produces:
INTRODUCTION TO ALGORITHMS
Sub Title
Third Edition
Thomas H. Cormen
Charles E. Leiserson
Ronald L. Rivest
Clifford Stein
Imprint
\MITimprint{The MIT Press\\
Cambridge, Massachusetts\\
London, England}
Copyright page
\begin{copyrightpage}
text….
\end{copyrightpage}
‹
The MIT Press
Cambridge, Massachusetts
London, England
User’s Guide
6
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Dedication page
\dedication{Dedication text}
Epigraph Page
\begin{epigraphpage}
text ….\source{Source text}
\end{epigraphpage}
Table of Contents
To generate a TOC, use:
\tableofcontents
List of Figures
To generate a List of Figures, use:
\listoffigures
List of Tables
To generate a List of Tables, use:
\listoftables
Contributors
\begin{contributors}
2014/5/27 12:42 Page xv
sample-6x9
\name{Contributors
Name}
\affil{Address}
\end{contributors}
#15
Contributors
Which
produces:
Thomas H. Cormen
Professor and Chair, Department of Computer Science, Massachusetts Institute
of Technology
Ronald L. Rivest
CSAIL, 32 Vassar Street, Room 32-G692, Cambridge MA 02139
User’s Guide
7
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Body Matter
At the start of the body matter, use the command “\mainmatter”.
For Part
sample-6x9
2014/5/27 12:42
\part{Role
of Algorithms}
Which produces:
I
Page 1 #17
ROLE OF ALGORITHMS
For Chapter
\chapter{The Role of Algorithms in Computing}
sample-6x9 2014/5/27 12:42 Page 1 #19
Which produces:
1
The Role of Algorithms in Computing
Thomas H. Cormen1
For1Professor
an Unnumbered
Chapter
and Chair, Department of Computer Science, Massachusetts Institute of Technology
\chapter*{Chapter Head}
ForWeAuthor
begin by examining the insertion sort algorithm to solve the sorting problem intro-
duced in Chapter 1. We define a “pseudocode” that should be familiar to you if you
have done computer programming, and we use it to show how we shall specify our
algorithms. Having specified the insertion sort algorithm, we then argue that it correctly sorts, and we analyze its running time. The analysis introduces a notation that
focuses on how that time increases with the number of items to be sorted. Following
our discussion of insertion sort, we introduce the divide-and-conquer approach to the
design of algorithms and use it to develop an algorithm called merge sort. We end with
an analysis of merge sorts running time.
—Test sentence
\author[Address Link no]{author name}
\author[1]{author name}
For Address
\affil[Author Link no]{Address}
What are algorithms? Why is the study of algorithms worthwhile? What is
the role of algorithms relative to other technologies used in computers? In this
chapter, we will answer these questions.
INTRODUCTION
This part will start you thinking about designing and analyzing algorithms. It
is intended to be a gentle introduction to how we specify algorithms, some of
the design strategies we will use throughout this book, and many of the fundamental ideas used in algorithm analysis. Later parts of this book will build
upon this base. Chapter 1 provides an overview of algorithms and their place
in modem computing systems. This chapter defines what an algorithm is and
lists some examples. It also makes a case that we should consider algorithms
as a technology, alongside technologies such as fast hardware, graphical user
interfaces, object-oriented systems, and networks.
‹
User’s Guide
8
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
sample-6x9
Example
1
2014/5/27 12:42 Page 1 #19
\author[1]{Thomas H. Cormen}
\affil[1]{Professor and Chair, Department of Computer
Science,
Massachusetts Institute of Technology}
The Role of Algorithms in Computing
Which produces:
Thomas H. Cormen1
1 Professor
and Chair, Department of Computer Science, Massachusetts Institute of Technology
We begin
by examining
insertion
sort algorithm
to solvein
thethe
sorting
problem
introIf an
author the
and
address
are present
file,
write
“\maketitle”
duced in Chapter 1. We define a “pseudocode” that should be familiar to you if you
the computer
end as programming,
in the following
example:
have done
and we use
it to show how we shall specify our
algorithms. Having specified the insertion sort algorithm, we then argue that it cor\author[1]{
rectly sorts, and
we analyze its} running time. The analysis introduces a notation that
focuses
that time }increases with the number of items to be sorted. Following
on how
\affil[1]{
our discussion of insertion sort, we introduce the divide-and-conquer approach to the
design\maketitle
of algorithms and use it to develop an algorithm called merge sort. We end with
an analysis of merge sorts running time.
—Test sentence
For Epigraph
What are algorithms? Why is the study of algorithms worthwhile? What is
\epigraph{Epigraph
the role
of algorithms relative to text}{Sentence}
other technologies used in computers? In this
chapter, we will answer these questions.
For Abstract
INTRODUCTION
\begin{abstract}
Text…
This part
will start you thinking about designing and analyzing algorithms. It
is intended
to be a gentle introduction to how we specify algorithms, some of
\end{abstract}
the design strategies we will use throughout this book, and many of the fundamental ideas used in algorithm analysis. Later parts of this book will build
upon this base. Chapter 1 provides an overview of algorithms and their place
in modem computing systems. This chapter defines what an algorithm is and
lists some examples. It also makes a case that we should consider algorithms
as a technology, alongside technologies such as fast hardware, graphical user
interfaces, object-oriented systems, and networks.
at
User’s Guide
9
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Heading Levels
For A head
\Ahead{Ahead title}
For Head Level 1
\section{Head Level 1 Title}
For Unnumbered Head Level 1
\section*{Head Level 1 Title}
For Head Level 2
\subsection{Head Level 2 Title}
For Unnumbered Head Level 2
\subsection*{Head Level 2 Title}
For Head Level 3
\subsubsection{Head Level 3 Title}
For Unnumbered Head Level 3
\subsubsection*{Head Level 3 Title}
For Head Level 4
\paragraph{Head Level 4 Title}
For Unnumbered Head Level 4
\ paragraph *{Head Level 4 Title}
‹
User’s Guide
10
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
For Head Level 5
\subparagraph{Head Level 5 Title}
For Unnumbered Head Level 5
\ subparagraph *{Head Level 5 Title}
For Head Level 6
\subsubparagraph{Head Level 6 Title}
For Unnumbered Head Level 6
\ subsubparagraph *{Head Level 6 Title}
For List Head
\listhead{list Head}
User’s Guide
11
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Number Head 4 (math)
sample-6x9 2014/5/27 12:42 Page 6 #24
This heading should be used for the following elements: definitions,
theorems, propositions, corollaries, lemmas, assumptions, and rules.
6
Part I
Definitions
\begin{definition}\label{def1}
C OROLLARY 2.2 Prove that the running time of an algorithm is �(g(n)) if
and only
if its worst-case running time is O(g(n)) and its best-case running
Text…
time is �(g(n)).
\end{definition}
When the first two properties hold, the loop invariant is true prior to every
iteration
of the loop. has
(Of course,
we are
free to use established facts other than
If the
definition
a title,
use:
the loop invariant itself to prove that the loop invariant remains true before
\begin{definition}[Title]
each iteration.)
We prefer not to get bogged\label{def1}
down in such formalism, and so
we rely on our informal analysis to show that the second property holds for
Text….
the outer
loop. We shall use this method of loop invariants to show correctness
later in\end{definition}
this chapter and in other chapters as well. We prefer not to get bogged
down in such formalism, and so we rely on our informal analysis to show that
the secondoutput:
property holds for the outer loop. We shall use this method of loop
Example
invariants to show correctness later in this chapter and in other chapters as well
in Definition 2.3.
D EFINITION 2.3 For any two functions f (n) and g(n), we have f (n) =
�(g(n)) if and only if f (n) = O(g(n)) and f (n) = �(g(n)). As an example of
the application of this theorem, our proof that an2 + bn + c = �(n2 ) for any
constants a, b, and c, where a > 0, immediately implies that an2 + bn + c =
�(n2) and an2 + bn + c = O(n2 ).
Note the similarity to mathematical induction, where to prove that a property holds, you prove a base case and an inductive step. Here, showing that
the invariant holds before the first iteration corresponds to the base case, and
Theorems
showing that the invariant holds from iteration to iteration corresponds to the
inductive step.
\begin{theorem}\label{thm1}
P ROPOSITION 2.4 For any two functions f (n) and g(n), we have f (n) =
Text…
�(g(n)) if and only if f (n) = O(g(n)) and f (n) = �(g(n)). As an example of
the application
of this theorem, our proof that an2 + bn + c = �(n2 ) for any
\end{theorem}
constants a, b, and c, where a > 0, immediately implies that an2 + bn + c =
�(n2) and an2 + bn + c = O(n2 ).
Propositions
The third property is perhaps the most important one, since we are using
the loop invariant to show correctness.1 Typically, we use the loop invariant
\begin{proposition}\label{prop1}
along with the condition that caused the loop to terminate. The termination
Text…
\end{proposition}
1 Not all authors define the asymptotic notations in the same way, although the various definitions
agree in most common situations. Some of the alternative definitions encompass functions that are
not asymptotically nonnegative, as long as their absolute values are appropriately bounded. Other
Corollaries
\begin{corollary}\label{cor1}
Text…
\end{corollary}
‹
User’s Guide
12
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Lemmas
\begin{lemma}\label{lem1}
Text…
\end{lemma}
Assumptions
\begin{assumption}\label{assum1}
Text…
\end{assumption}
Rules
\begin{rules}\label{rul1}
Text…
\end{rules}
User’s Guide
13
sample-6x9 2014/5/27 12:42 Page 9 #27
Number Head 5 (math)
Role of Algorithms
9
sort. The for loop header in line 1 is for j = 2 to A. length, and so when this loop
terminates,
j = A.length + 1 (or,
equivalently, j =
n + 1,
since n = A.
length).
This
heading
should
be
used
for
the following elements: proofs, examples,
We use the keyword to when a for loop increments its loop counter in each
iteration,
and
we
use
the
keyword
downto
when
a
for
loop
decrements
its
loop
remarks,
demonstrations, and solutions.
counter.
Demonstrations 2.1 For any two functions f (n) and g(n), we have f (n) =
�(g(n)) if and only if f (n) = O(g(n)) and f (n) = �(g(n)). As an example of
Proofs
the application of this theorem, our proof that an + bn + c = �(n ) for any
2
2
constants a, b, and c, where a > 0, immediately implies that an2 + bn + c =
�(n2) and an2 + bn + c = O(n2 ).
\begin{proof}
Text…
Solution 2.1 For any two functions f (n) and g(n), we have f (n) = �(g(n)) if
and only if f (n)
= O(g(n)) and f (n) = �(g(n)). As an example of the appli\end{proof}
cation of this theorem, our proof that an + bn + c = �(n ) for any constants
A multiple assignment of the form i = j = e assigns to both variables i and
j the value of expression e; it should be treated as equivalent to the assignment
j = e followed by the assignment i = j.
2
2
a, b, and c, where a > 0, immediately implies that an2 + bn + c = �(n2 ) and
an2 + bn + c = O(n2 ).
Proof output:
Variables (such as i, j, and key) are local to the given procedure. We shall
not use global variables without explicit indication.
Proof. We use the bounds in Lemma 4.3 to evaluate the summation (4.21)
from Lemma 4.2. For case 1, we have
T(n) = �(nlogb a ) + O(nlogb a )
= �(nlogb a ),
and for case 2,
T(n) = �(nlogb a ) + �(nlogb a lgn)
= �(nlogb a lgn).
For case 3,
T(n) = �(nlogb a ) + �(f (n))
= �(f (n)),
because f (n) = �(nlogb a+� ).
Examples
\begin{examples}
Text…
\end{examples}
Remarks
\begin{remark}
Text…
\end{remark}
Demonstrations
\begin{demonstrations}
Text…
\end{demonstrations}
Solutions
\begin{solution}
Text…
\end{solution}
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
User’s Guide
14
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Lists
Numbered Lists
\begin{enumerate}
sample-6x9
\item
text…2014/5/27
\item text…
\end{enumerate}
12:42 Page 10 #28
10 lists with double-digit items, use:
Part I
For
\begin{enumerate}[10.]
\item text…
\item
text… by specifying the array name followed by the
We access
array elements
index in square brackets. For example, Ai indicates the i th element of the array
\end{enumerate}
A. The notation “. . .” is used to indicate a range of values within an array. Thus,
A1 .lists
. . j indicates
the subarray ofitems,
A consisting
For
with triple-digit
use:of the j elements A1, A2, . . . , Aj.
\begin{enumerate}[100.]
Kinds
\itemof text…
2.4 What
Problems are Solved by Algorithms?
\item text…
2.4.1 Numbered Lists
\end{enumerate}
These lists are far from exhaustive (as you again have probably surmised from
Example
this book’soutput:
heft), but exhibit two characteristics that are common to many interesting algorithmic problems:
1. They have many candidate solutions, the overwhelming majority of which
do not solve the problem at hand. Finding one that does, or one that is
“best,” can present quite a challenge.
2. They have practical applications. Of the problems in the above list, finding
the shortest path provides the easiest examples. A transportation firm, such
as a trucking or railroad company, has a financial interest in finding shortest
paths through a road or rail network because taking shorter paths results in
lower labor and fuel costs. Or a routing node on the Internet may need
to find the shortest path through the network in order to route a message
quickly. Or a person wishing to drive from New York to Boston may want
to find driving directions from an appropriate Web site, or she may use her
GPS while driving.
a. No black-heights in the tree have changed.
b. No red nodes have been made adjacent. Because y takes z’s place in the
tree, along with z’s color, we cannot have two adjacent red nodes at y’s
new position in the tree. In addition, if y was not z’s right child, then y’s
original right child x replaces y in the tree. If y is red, then x must be
black, and so replacing y by x cannot cause two red nodes to become
adjacent.
c. Since y could not have been the root if it was red, the root remains black.
k
i. Otherwise, u = 22 for some integer k ≥ 1, so that u ≥ 4. In addition
to the universe size u, the data structure pro to-vEB (u) contains the
following attributes, illustrated.
‹
User’s Guide
15
sample-6x9 2014/5/27 12:42 Page 10 #28
Numbered Sublists
10
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Part I
\begin{enumerate}[a.]
\item text…
We access
array
elements
by specifying the array name followed by the
\item
text…
index in square brackets. For example, Ai indicates the i th element of the array
A. The notation
“. . .” is used to indicate a range of values within an array. Thus,
\end{enumerate}
A1 . . . j indicates the subarray of A consisting of the j elements A1, A2, . . . , Aj.
Numbered Sub-sublists
2.4 What
Kinds of Problems are Solved by Algorithms?
\begin{enumerate}[iii.]
\item
2.4.1 Numbered
Liststext…
These lists
from exhaustive
are far
\item
text… (as you again have probably surmised from
this book’s heft), but exhibit two characteristics that are common to many inter\end{enumerate}
esting algorithmic
problems:
1. They have
many candidate solutions, the overwhelming majority of which
Example
output:
do not solve the problem at hand. Finding one that does, or one that is
“best,” can present quite a challenge.
2. They have practical applications. Of the problems in the above list, finding
the shortest path provides the easiest examples. A transportation firm, such
as a trucking or railroad company, has a financial interest in finding shortest
paths through a road or rail network because taking shorter paths results in
lower labor and fuel costs. Or a routing node on the Internet may need
to find the shortest path through the network in order to route a message
quickly. Or a person wishing to drive from New York to Boston may want
to find driving directions from an appropriate Web site, or she may use her
GPS while driving.
a. No black-heights in the tree have changed.
b. No red nodes have been made adjacent. Because y takes z’s place in the
tree, along with z’s color, we cannot have two adjacent red nodes at y’s
new position in the tree. In addition, if y was not z’s right child, then y’s
original right child x replaces y in the tree. If y is red, then x must be
black, and so replacing y by x cannot cause two red nodes to become
adjacent.
c. Since y could not have been the root if it was red, the root remains black.
k
i. Otherwise, u = 22 for some integer k ≥ 1, so that u ≥ 4. In addition
to the universe size u, the data structure pro to-vEB (u) contains the
following attributes, illustrated.
‹
User’s Guide
16
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
sample-6x9 2014/5/27 12:42 Page 12 #30
Bullet
Lists
12
Part I
\begin{itemize}
\item text…
overall running
timetext…
on a problem of size n in terms of the running time on
\item
smaller inputs. We can then use mathematical tools to solve the recurrence and
provide\end{itemize}
bounds on the performance of the algorithm.
Bullet
2.4.4 Sublists
Bullet List
SortingSame
is by no
theLists.
only computational problem for which algorithms
asmeans
Bullet
have been developed. (You probably suspected as much when you saw the size
Example
output:
of this book.)
Practical applications of algorithms are ubiquitous and include
the following examples:
• The Human Genome Project has made great progress toward the goals of
identifying all the 100,000 genes in human DNA, determining the sequences
of the 3 billion chemical base pairs that make up human DNA, storing this
information in databases, and developing tools for data analysis.
• Each of these steps requires sophisticated algorithms. Although the solutions to the various problems involved are beyond the scope of this book,
many methods to solve these biological problems use ideas from several
of the chapters in this book, thereby enabling scientists to accomplish
tasks while using resources efficiently.
• The savings are in time, both human and machine, and in money, as more
information can be extracted from laboratory techniques.
• The Internet enables people all around the world to quickly access and
retrieve large amounts of information. With the aid of clever algorithms,
sites on the Internet are able to manage and manipulate this large volume of
data. Examples of problems that make essential use of algorithms include
finding good routes on which the data will travel.
• Electronic commerce enables goods and services to be negotiated and
exchanged electronically, and it depends on the privacy of personal informaUnnumbered
Lists
tion such as credit
card numbers, passwords, and bank statements. The core
technologies used in electronic commerce include public-key cryptography
\begin{unlist}
and digital
signatures (covered in Chapter 31), which are based on numerical algorithms and number theory. The savings are in time, both human and
\item Text…
machine, and in money, as more information can be extracted.
\item Text…
They have practical applications. Of the problems in the above list, finding
\end{unlist}
the shortest
path provides the easiest examples. A transportation firm, such as a
trucking or railroad company, has a financial interest in finding shortest paths
‹
User’s Guide
17
sample-6x9 2014/5/27 12:42 Page 13 #31
Role of Algorithms
Descriptive
Lists
13
\begin{descriptive}
\item \head{Head text}
through a road or rail network because taking shorter paths results in lower
laborand fuel
costs.\head{Head text}
\item
\end{descriptive}
2.4.5 Descriptive List
Example
output:
Our first algorithm, insertion sort, solves the sorting problem introduced in
Chapter 1:
1. Input A sequence of n numbers {a1 , a2 , . . . , an ).
2. Output A permutation (reordering) {a�1 , a�2 , . . . , a�n ) of the input sequence
such that a�1 ≤ a�2 ≥ · · · ≤ a�n .
3. Divide Divide the n-element sequence to be sorted into two subsequences
of n/2 elements each.
The numbers that we wish to sort are also known as the keys. Although
conceptually we are sorting a sequence, the input comes to us in the form of
an array with n elements.
2.4.6 List With Heading
Consider the problem of adding two n-bit binary integers, stored in two nelement arrays A and B. The sum of the two integers should be stored in binary
form in an (n + 1)-element array C. State the problem formally and write pseudocode for adding the two integers.
Analyzing Algorithms
k
1. Otherwise, u = 22 for some integer k ≥ 1, so that u ≥ 4. In addition to the
universe size u, the data structure pro to-vEB (u) contains the following
attributes, illustrated.
√
√
√
2. An array cluster 0. . u − 1 of u pointers, each to a pro to-vEB ( u)
structure.
2.4.7 Notation
MDA(H)
Maximum domain of attraction of the value distribution H
N(μ, σ 2 )
Gaussian (normal) distribution with mean μ, variance σ 2
N(μ, �)
Multivariate Gaussian (normal) distribution with mean vector μ
and covariance matrix �
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
User’s Guide
18
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Figures
Figure
\begin{figure}[tb]
\includegraphics{images-name}
\caption{ caption text\label{fig1}}
\end{figure}
Meaning of [tb]
t – top placement
b – bottom placement
Landscape Figure
\begin{sidewaysfigure}
\includegraphics{image-1}
\caption{ caption text\label{fig1}}
\end{sidewaysfigure}
User’s Guide
19
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Tables
For tables, use the processtable{caption here}{tabular here}
{table footnote} tag:
\begin{table}[!t]
\processtable{caption text\label{time-use}}
{
\begin{tabular*}{26pc}{@{\extracolsep{\fill}}lcc@{}}
\Toprule
& \multicolumn{1}{c}{Employed} & {Unemployed} \\
\Midrule
{Sleep} & 496 & 555 \\
{Personal care and eating} & 110 & 197 \\
{Home production, shopping, care of others} & 158 & 254 \\
{Leisure, travel, sports, and socializing} & 320 & 442\\
{Work} & 325 & 210 \\
{Job search} & 321 & 323 \\
\Botrule
sample-6x9 2014/5/27 12:42 Page 18 #36
\end{tabular*}}
{Note: This is where authors provide additional information
about the data, including whatever notes are needed.}
18 \end{table}
Part I
Which produces:
Table 2.1
Average Minutes Per Day by Activity and Employment Status in the United States in 2003–2006.
Sleep
Personal care and eating
Home production, shopping, care of others
Leisure, travel, sports, and socializing
Work
Job search
Employed
Unemployed
496
110
158
320
325
321
555
197
254
442
210
323
Note: This is where authors provide additional information about the data, including whatever
notes are needed.
tree. If y is red, then x must be black, and so replacing y by x cannot cause two red
nodes to become adjacent.
The element x, where 0 ≤ x < u, is recursively stored in the cluster numbered high (x)
as element low (x) within that cluster.
Even for inputs of a given size, an algorithm‘s running time may depend on
which input of that size is given. For example, in INSERTION-SORT, the best
case occurs if the array is already sorted. For each j = 2, 3, . . . , n, we then
find that Ai ≤ key in line 5 when i has its initial value of j − 1. Thus tj = 1 for
j = 2, 3, . . . , n, and the best-case running time is
T(n) = c1 n + c2 (n − 1) + c4 (n − 1) + c5 (n − 1) + c8 (n − 1)
‹
User’s Guide
20
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Landscape Table
\begin{sidewaystable}
\processtable{caption text here}{
\begin{tabular}{ll}
\Toprule
Head & Head\\
\Midrule
1 & 2\\
3 & 4\\
\Botrule
\end{tabular}
}{footnote text here}
\end{sidewaystable}
Unnumbered Table
\begin{table}[!h]
\unprocesstable{}{
\begin{tabular}{lllll}
\Toprule
Stubhead & \( df \) & \( f \) & \( \eta \) & \( p \) \\
\Midrule
& \multicolumn{4}{c}{Spanning text} \\
Row 1 & 1
& 0.67 & 0.55
& 0.41 \\
Row 2 & 2
& 0.02 & 0.01
& 0.39 \\
Row 3 & 3
& 0.15 & 0.33
& 0.34 \\
Row 4 & 4
& 1.00 & 0.76
& 0.54 \\
\Botrule
\end{tabular}}{}
\end{table}
User’s Guide
21
sample-6x9 2014/5/27 12:42 Page 21 #39
LaTeX Template
Guidance
Basic Class File
Box Head
Front Matter
Role of Algorithms
21
For a box number and title, use:
Book Title
\boxhead{Common Functions}
Body Matter
Heading Levels
Which produces:
Number Head 4 (math)
Number Head 5 (math)
Box 1
Lists
Common Functions
Figures
Tables
This section reviews some standard mathematical functions and notations and explores
Box the
Box
relationships among them. It also illustrates the use of the asymptotic notations. Program Coding
2 ) for
As an example of the application of this theorem, our proof an2 + bn + c = �(n
\begin{mdframed}
Dialogue
�(n2 )
any
constants a, b, and c, where a > 0, immediately implies that an2 + bn + c =Exercises
Text….
and
an2 + bn + c = O(n2 ). In practice, rather than using Theorem 3.1 to obtain asymptotic
\end{mdframed}
Appendix
upper and lower bounds from asymptotically tight bounds, as we did for this example,
Bibliography
weinside
usuallyBox
use it to prove asymptotically tight bounds from asymptotic upper and
lower
Extract
Index
bounds. We have already seen how asymptotic notation can be used within mathematical
formulas.
For example, in introducing O-notation.
\begin{extract}
Box
Text…
Although the solutions to the various problems involved are beyond the scope of
\end{extract}
this book, many methods to solve these biological problems use ideas from several
of the
chapters
Heading Levels
within
a Boxin this book, thereby enabling scientists to accomplish tasks while
using resources efficiently. The savings are in time, both human and machine, and
money, asgiven
more for
information
be extracted
from levels
laboratory techniques.
Use the sameincommands
“Headingcan
levels”
to create head
within a box.
The running time of insertion sort therefore belongs to both �(n) and O(n2 ), since it
falls anywhere between a linear function of n and a quadratic function of n. Moreover,
these bounds are asymptotically as tight as possible: for instance, the running time of
insertion sort is not �(n2 ), since there exists an input for which insertion sort runs in �(n)
time (e.g., when the input is already sorted). It is not contradictory, however, to say that the
worst-case running time of insertion sort is �(n2 ), since there exists an input that causes
the algorithm to take �(n2 ) time.
We have already seen how asymptotic notation can be used within mathematical formulas. For example, in introducing O-notation, we wrote n = O(n2 ). We might also write
2n2 + 3n + 1 = 2n2 + �(n). How do we interpret such formulas?
T(n) = c1 n + c2 (n − 1) + c4 (n − 1) + c5
n
j=2
tj + c6
n
j=2
(tj − 1)
When the asymptotic notation stands alone (that is, not within a larger formula) on the
right-hand side of an equation (or inequality), as in n = O(n2 ), we have already defined
the equal sign to mean set membership: n ∈ O(n2 ). In general, however, when asymptotic
notation appears in a formula, we interpret it as standing for some anonymous function
that we do not care to name. For example, the formula 2n2 + 3n + 1 = 2n2 + �(n) means
User’s Guide
22
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Program Coding
\begin{lstlisting}[language=C]
void initializeMyStruct( myStruct* ms ) {
static
int modulo3
= 0 Page 19 #37
sample-6x9
2014/5/27 12:42
if (modulo3 == 2) {
modulo3 = 0;
if (checkDay(‘tue’)) {
Role of Algorithms
19
ms->a = 1;
}
(see Appendix
of how
A for a review
} else
{ to solve these summations), we find that
in the worst case, the running time of INSERTIONSORT is
modulo3++;
n(n + 1)
−1
T(n) = c1 n + c2 (n − 1) + c4 (n − 1) + c5
= 0; 2
ms->a
n(n − 1)
n(n − 1)
+} C7
+ c8 (n − 1)
+
c6
2
2
c
c6 c7 2
c5 c6 c7
5
+ +
n } + c1 + c2 + c4 +
− −
+ c8 n
= 2
2
2
2
2
2
−
(c2 + c4 + c5 + c8 ).
\end{lstlisting}
We can express this worst-case running time as an2 + bn + c for constants a, b,
Which
and c thatproduces:
again depend on the statement costs ci ; it is thus a quadratic function
of n.
void initializeMyStruct( myStruct* ms ) {
static int modulo3 = 0;
if (modulo3 == 2) {
modulo3 = 0;
if (checkDay(’tue’)) {
ms->a = 1;
}
} else {
modulo3++;
ms->a = 0;
}
}
An important notational convention we shall adopt is that logarithm functions will apply only to the next term in the formula, so that lgn + k will mean
lgn) +k and not lg(n + k). If we hold b > 1 constant, then for n > 0, the function logb n is strictly increasing.
2.5.2 Dialogue
Given a well-defined notion of the remainder of one integer when divided
by another, it is convenient to provide special notation to indicate equality
of remainders. If (a mod n) = (bmod n), we write a ≡ b(mod n) and say that a
is equivalent to b, modulo n. In other words, a ≡ b(mod n) if a and b have the
same remainder when divided by n. Equivalently, a ≡ b(mod n) if and only
User’s Guide
23
Dialogue
20
\begin{dialogue}
\speak{Vladimir} Where are all these corpses from?
\speak{Estragon} These skeletons.
\speak{Vladimir} A charnel-house! A charnel-house!
\speak{Estragon} I’m in hell!
\speak{Vladimir} Where were you?
\speak{Estragon}
coming
there too!
sample-6x9 2014/5/27 They’re
12:42 Page
20 #38
\speak{Vladimir} We’re surrounded! makes a rush towards
back.
Imbecile! There’s no way out there.
Part I
There! Not a soul in sight! Off you go! Quick!
\end{dialogue}
Which
produces:
if n is a divisor
of b − a. We write a �≡ b(mod n) if a is not equivalent to b,
modulo n.
Vladimir Whare are all these corpses from?
Estragon These skeletons.
Vladimir A charnel-house! A charnel-house!
Estragon I’m in hell!
Vladimir Where were you?
Estragon They’re coming there too!
Vladimir We’re surrounded! makes a rush towards back. Imbecile! There’s
no way out there. There! Not a soul in sight! Off you go! Quick!
For any integer a and any positive integer n, the value amod n is the remainder (or residue) of the quotient a/n. We can extend our notation to the case
of two parameters n and m that can go to infinity independently at different in
rates.
2.5.3 In Text Table
For any real number x, we denote the greatest integer less than or equal to x by
�x� (read the floor of x) and the least integer greater than or equal to x by �x�
(read “the ceiling of x). For all real x,
Stubhead
Row 1
Row 2
Row 3
Row 4
df
1
2
3
4
f
η
Spanning text
0.67
0.55
0.02
0.01
0.15
0.33
1.00
0.76
p
0.41
0.39
0.34
0.54
We can extend our notation to the case of two parameters n and m that can
go to infinity independently at different rates. For a given function g(n, m), we
denote by O(g(n, m)) the set of functions. For any integer a and any positive
integer n, the value amod n is the remainder (or residue) of the quotient a/n.
We can extend our notation to the case of two parameters n and m that can go
to infinity independently at different in rates.
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
User’s Guide
24
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Exercises
Exercises should be placed in a separate, unnumbered chapter. Use the
command \backmatter before “\begin{exercises}”.
\backmatter
\begin{exercises}
\begin{enumerate}
\item Text…
\item Text…
\end{enumerate}
Text…
\end{exercises}
All heading levels in exercises are same as regular heading levels.
User’s Guide
Appendix
\begin{appendices}
\chapter{Summations}
Text….
\end{appendices}
To create headings within an appendix, use the regular heading commands.
25
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
User’s Guide
26
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index
Bibliography
\begin{thebibliography}{11}
\bibitem{1} Milton Abramowitz and Irene A. Stegun, editors.
Handbook \ of Mathematical Functions. Dover, 1965.
\bibitem{2} G. M. Adel fson-Vel fski.. and E. M. Landis. An algorithm
for the organization of information. Soviet Mathematics Doklady,
(5):1259.1263, 1962.
sample-6x9 2014/5/27 12:42 Page 37 #55
\end{thebibliography}
Which produces:
Bibliography
[1] Milton Abramowitz and Irene A. Stegun, editors. Handbook of Mathematical Functions.
Dover, 1965.
[2] G. M. Adelfson-Velfski.. and E. M. Landis. An algorithm for the organization of information.
Soviet Mathematics Doklady, 3(5):1259.1263, 1962.
[3] Alok Aggarwal and Jeffrey Scott Vitter. The input/output complexity of sorting and related
problems. Communications of the ACM, 31(9):1116.1127, 1988.
[4] Manindra Agrawal, Neeraj Kayal, and Nitin Saxena. PRIMES is in P. Annals of Mathematics, 160(2):781.793, 2004.
Sample Coding for Crosslink
[5] Alfred V. Aho, John E. Hopcroft, and Jeffrey D. Ullman. The Design and Analysis of Computer Algorithms. Addison-Wesley, 1974.
[6] Alfred V. Aho, John E. Hopcroft, and Jeffrey D. Ullman. Data Structures and Algorithms.
Addison-Wesley, 1983.
[7] Ravindra K. Ahuja, Thomas L. Magnanti, and James B. Orlin. Network Flows: Theory,
Algorithms, and Applications. Prentice Hall, 1993.
[8] Ravindra K. Ahuja, Kurt Mehlhorn, James B. Orlin, and Robert E. Tarjan. Faster algorithms
for the shortest path problem. Journal of the ACM, 37(2):213.223, 1990.
[9] Ravindra K. Ahuja and James B. Orlin. A fast and simple algorithm for the maximum flow
problem. Operations Research, 37(5):748.759, 1989.
[10] Ravindra K. Ahuja, James B. Orlin, and Robert E. Tarjan. Improved time bounds for the
maximum flow problem. SIAM Journal on Computing, 18(5):939.954, 1989.
[11] MiklLos Ajtai, Nimrod Megiddo, and Orli Waarts. Improved algorithms and analysis for
secretary problems and generalizations. In Proceedings of the 36th Annual Symposium on
Foundations of Computer Science, pages 473.482, 1995.
Which produces:
User’s Guide
Index
To generate an index:
1. Before \begin{document}, use:
\usepackage{makeidx}
\makeindex
2. Enter \index{term} or \index{term!subterm} or
index{term!subterm!subterm}
Be careful! There must be no spaces before or after the ‘!’ or your subterms
will not alphabetize correctly.
3. Run LaTeX, producing filename.idx.
4. Type ‘makeindx filename’ at the command line to produce filename.ind.
The index file, filename.ind can be edited if necessary.
5. To insert the generated index within your files, use:
\printindex
\documentclass{book}
\usepackage{makeidx}
\makeindex
\begin{document}
Borden’s symbol, Elsie the cow, is a Jersey, a kind of
cow characterized by a caramel colored coat and
large dark eyes.\index{Cows}\index{Cows!Jersey}\
index{Cows!Jersey!Brown eyed}...
\printindex
\end{document}
27
LaTeX Template
Guidance
Basic Class File
Front Matter
Book Title
Body Matter
Heading Levels
Number Head 4 (math)
Number Head 5 (math)
Lists
Figures
Tables
Box
Program Coding
Dialogue
Exercises
Appendix
Bibliography
Index