Alan Kaminsky Department of Computer Science Rochester Institute of Technology 4486 + 2220 = 6706
Home Page
Theory of Computer Algorithms 4005-800-70 Winter Quarter 2003
Course Page

4005-800-70 Theory of Computer Algorithms
How To Use LaTeX

Prof. Alan Kaminsky -- Winter Quarter 2003
Rochester Institute of Technology -- Department of Computer Science

Install LaTeX
Create the LaTeX Input File
Create the LaTeX Output File
Create the PDF File
LaTeX Books and Links


Install LaTeX

The commands for using LaTeX are already installed on the Computer Science Department's Unix systems.

The commands for using LaTeX are included in most Linux distributions.

The commands for using LaTeX are included in Cygwin. Cygwin is a free Linux-like environment for Microsoft Windows, available from http://www.cygwin.com/.


Create the LaTeX Input File

Using your favorite text editor, create a LaTeX input file named "<something>.tex". I'm not going to explain here what goes into the LaTeX input file. Get a book on LaTeX, or look up one of the LaTeX tutorials on the Web. (See the LaTeX Books and Links below.)

Below is an example of a LaTeX input file. You can also download the example input file, latexexample.tex.
\documentclass[10pt,letterpaper,fleqn]{article}

\setlength{\hoffset}{-1in}
\setlength{\evensidemargin}{1in}
\setlength{\oddsidemargin}{1in}
\setlength{\marginparsep}{0pt}
\setlength{\voffset}{-1.25in}
\setlength{\topmargin}{0.5in}
\setlength{\headheight}{0.25in}
\setlength{\headsep}{0.25in}
\setlength{\textwidth}{6.5in}
\setlength{\textheight}{9in}
\setlength{\footskip}{0.5in}

\newcommand{\dif}{\mathrm{d}}
\newcommand{\me}{\mathrm{e}}
\newcommand{\mi}{\mathrm{i}}
\setlength{\mathindent}{0.5in}

\begin{document}

\title{Theory of Computer Algorithms\\
Module 1 Homework Assignment}

\author{Alan Kaminsky\\
ark@cs.rit.edu}

\date{December 3, 2003}

\maketitle

\section{Problem 1}

(Cormen, Leiserson, Rivest, \& Stein, Exercise 1.1-1, page 10)

Sorting is used, for example, in data mining of web server logs.
The web server records an entry in the web log
each time a user requests a web page.
Each web log entry contains
the IP address of the user making the request,
the date and time of the request,
and the web page that was requested.
A data mining application
might wish to examine the \emph{user sessions,}
where a user session is defined to be
a series of requests from the same IP address
within a certain time span.
The sessions can be identified
by sorting the web log entries
based on their IP addresses,
then partitioning each IP address's entries into sessions
based on the dates and times.

\section{Problem 2}

(Cormen, Leiserson, Rivest, \& Stein, Exercise 1.2-2, page 13)

This insertion sort will beat this merge sort
if the insertion sort takes fewer steps than the merge sort.
Solving the inequality:
\begin{eqnarray}
8 n^2 & < & 64 n \lg n \\
n^2 & < & 8 n \lg n \\
n & < & 8 \lg n
\end{eqnarray}
(3) is true for $n \le 43$:
$n = 43$ is less than $8 \lg 43 = 43.41$,
but $n = 44$ is greater than $8 \lg 44 = 43.68$.
So this insertion sort beats this merge sort
for arrays of length 43 or less.

\end{document}


Create the LaTeX Output File

LaTeX compiles the input file to create a formatted output file named "<something>.dvi". The output file is known as a "device independent" (DVI) file because it can be viewed or printed on a variety of devices. To create the DVI file, run the latex command and give the name of the input file; for example:

latex latexexample.tex

To display the DVI file on the screen, run the xdvi command and give the name of the DVI file; for example:

xdvi latexexample.dvi

You can simultaneously edit the input file in one window and display the DVI file in another window. After changing the input file in the text editor, re-run the latex command. The DVI viewer will automatically display the new contents of the DVI file.


Create the PDF File

Converting the DVI file to an Adobe Acrobat PDF file is a two-step process: First convert the DVI file to a PostScript file, then convert the PostScript file to a PDF file. (There are commands to convert DVI directly to PDF, but these commands do not give as good results as the two-step process.) Run these two commands:

dvips -Pcmz -t letter -o latexexample.ps latexexample.dvi
ps2pdf latexexample.ps

The "-Pcmz" option tells the dvips command to include LaTeX's bitmapped fonts in the PostScript file; without this option, mathematical formulas and certain other symbols end up looking lousy. The "-t letter" option tells the dvips command to specify U.S. letter size paper in the PostScript file; without this option, the default is A4 size paper. The "-o latexexample.ps" option tells the dvips command to put the output in the specified PostScript file; without this option, the default is to send the output directly to the printer.

After running the above two commands, you can use Adobe Acrobat to display and print the PDF file. Here is the PDF file generated from the above example input file: latexexample.pdf

You can use the ps2pdf command to convert any PostScript file to a PDF file. For example, you can tell a word processor like Microsoft Word or OpenOffice Writer to print a document into a PostScript file, then you can convert that to a PDF file.


LaTeX Books and Links

Helmut Kopka and Patrick W. Daly. A Guide to LaTeX, Third Edition. Addison-Wesley, 1999.

Tobias Oetiker, Hubert Partl, Irene Hyna, and Elisabeth Schlegl. "The Not So Short Introduction to LaTeX 2e, or LaTeX 2e in 131 minutes." http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf
Contents:
Chapter 1. Things You Need to Know
Chapter 2. Typesetting Text
Chapter 3. Typesetting Mathematical Formulae
Chapter 4. Specialities
Chapter 5. Producing Mathematical Graphics
Chapter 6. Customising LaTeX

Try typing "latex tutorial" into Google; the top five hits are:

David R. Wilkins. "Getting Started With LaTeX." http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/

Cornell University Computer Science Department. "Beginning LaTeX." http://www.cs.cornell.edu/Info/Misc/LaTeX-Tutorial/LaTeX-Home.html

Norm Matloff. "Norm Matloff's LaTeX Tutorial." http://heather.cs.ucdavis.edu/~matloff/latex.html

Brian Fiedler. "LaTeX Tutorial." http://it.metr.ou.edu/latex/

C. T. J. Dodson. "PDF LaTeX By Example." http://www.ma.umist.ac.uk/kd/latextut/pdfbyex.htm

Theory of Computer Algorithms 4005-800-70 Winter Quarter 2003
Course Page
Alan Kaminsky Department of Computer Science Rochester Institute of Technology 4486 + 2220 = 6706
Home Page
Copyright © 2003 Alan Kaminsky. All rights reserved. Last updated 08-Dec-2003. Please send comments to ark­@­cs.rit.edu.