Homework for Latex - Introduction to Algorithms and Data Structures | CSCI 0160, Assignments of Data Structures and Algorithms

Material Type: Assignment; Class: Introduction to Algorithms and Data Structures; Subject: Computer Science; University: Brown University; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 02/24/2010

koofers-user-9na
koofers-user-9na 🇺🇸

10 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 16 - Homework # (Latex Handout) C. S. Student (login)
Homework # (Latex Handout)
by Laura Parkinson
1 Latex
Latex helps you make your homework pretty. It makes us happy when you use it. The best
way to learn is by example, so here are some examples of pretty much everything you’ll need for
homeworks. You can use this document as a template for your homeworks. For more examples
and a great tutorial, go to Latex Guide. For a more extensive, but also great tutorial, go to Longer
Latex Guide.
2 How to use this guide
You will get the most out of this guide if you open the .tex file that generated it and read the two
side by side. The guide was designed to be read this way. The .tex file can be found on the course
site, here.
3 Kile
Kile is my favorite editor for Latex. You can run it by typing kile into your terminal, or open a
.tex file in it by typing kile filename.tex. I find it useful to open Kile and Xpdf side by side.
Then when I make the pdf from Kile (by clicking the blue gear with a pdf symbol), I can just type
‘r’ (for refresh) into Xpdf and see the updated pdf. The pdf will be created in the same folder that
your .tex file is in.
Two wonderful things about Kile are:
All the shortcuts on the left,
One button pdf-making.
4 Code
Here is an example of putting code in your homework:
public static int[] bubblesort(int[] numbers) {
boolean swapped = true;
for(int i = numbers.length - 1; i > 0 && swapped; i--) {
swapped = false;
for (int j = 0; j < i; j++) {
if (numbers[j] > numbers[j+1]) {
int temp = numbers[j];
pf3
pf4
pf5

Partial preview of the text

Download Homework for Latex - Introduction to Algorithms and Data Structures | CSCI 0160 and more Assignments Data Structures and Algorithms in PDF only on Docsity!

Homework # (Latex Handout)

by Laura Parkinson

1 Latex

Latex helps you make your homework pretty. It makes us happy when you use it. The best way to learn is by example, so here are some examples of pretty much everything you’ll need for homeworks. You can use this document as a template for your homeworks. For more examples and a great tutorial, go to Latex Guide. For a more extensive, but also great tutorial, go to Longer Latex Guide.

2 How to use this guide

You will get the most out of this guide if you open the .tex file that generated it and read the two side by side. The guide was designed to be read this way. The .tex file can be found on the course site, here.

3 Kile

Kile is my favorite editor for Latex. You can run it by typing kile into your terminal, or open a .tex file in it by typing kile filename.tex. I find it useful to open Kile and Xpdf side by side. Then when I make the pdf from Kile (by clicking the blue gear with a pdf symbol), I can just type ‘r’ (for refresh) into Xpdf and see the updated pdf. The pdf will be created in the same folder that your .tex file is in.

Two wonderful things about Kile are:

  • All the shortcuts on the left,
  • One button pdf-making.

4 Code

Here is an example of putting code in your homework:

public static int[] bubblesort(int[] numbers) { boolean swapped = true; for(int i = numbers.length - 1; i > 0 && swapped; i--) { swapped = false; for (int j = 0; j < i; j++) { if (numbers[j] > numbers[j+1]) { int temp = numbers[j];

numbers[j] = numbers[j+1]; numbers[j+1] = temp; swapped = true; } } } return numbers; }

5 Lists

  1. Enumerate automatically makes appropriate
  2. numbers or letters at the start of your
  3. list items.

a. Itemize uses bullets unless you make labels.

  • This has no label. i. This has a label. (a) Nested lists (b) of the same kind (c) look different

6 Tables

Perhaps you would like to put a table in your homework—here is how. Note that ’lll’ means three left-justified columns, whereas ’lcr’ would be a left-justified column, a center-justified column, and a right-justified column. Also, in a table (and in general) double backslash creates a new line.

Name Street Number Other random number Anastasia 1441 13577893 Bob 6461 9085653233

If you want lines on your table, just put them there with vertical bars and \hline.

Name Street Number Other random number Anastasia 1441 13577893 Bob 6461 9085653233

7.4 Big-O Notation

Big-O notation is just written with a big O, as in O(n log n).

7.5 Other random stuff that will be helpful

  • Floors and ceilings: bxc and dxe
  • Comparison: {≤, ≥, >, <, =, 6 =}
  • Macros:
    • This is in code;
    • I write n log n a lot.
    • { x | 1, 2, 3 }.
  • Special characters:
    • \ (backslash) - escapes, begins macros
    • ˜ (tilde) - an unbreakable space
    • (underscore) - subscripts in math mode (they cause errors outside of math mode)
    • ˆ (superscript) - superscripts in math mode (they cause errors outside of math mode)
    • { , } (curly brackets) - group commands

8 Images

You can also include images, such as this one:

9 Pseudocode

Surround your pseudocode with this environment, which will both respect your tabs and line breaks and allow M α † h formatting to work. This environment comes with the package /course/cs016/latex/cs016.sty which is included at the top of this file.

10 If you’re super fancy

Firstly, you can define macros by putting something like this at the top of your homework:

\newcommand{\command}[# args]{whatever you want using #arg1 #arg2 #argEtc}

Secondly, you can reflect, rotate, and scale text, and anything else:

like this!

Thirdly, you can include packages by putting this at the top of your homework:

\usepackage{package name}

Lastly, if you look at the CS 16 homeworks and think, “I want to do exactly that”, there is hope for you! The CS 16 documents use a special file: the path of this file is /course/cs016/bin/cs16.cls. You will need to add /course/cs016/bin to Settings > Configure Kile... > Latex

TEXINPUTS and you will need to replace \documentclass[11pt]{article} at the top of your homework with \documentclass{cs16}. However, if you want to do this, it’s at your own risk: the TAs have been instructed not to help you.