Algorithms Homework: General Specifications
These will apply to all homeworks unless specifically overridden
for a given assignment (which we do not expect to do!).
- Your programs must be written in Java or C/C++.
- Update: You may submit multiple files for a problem - however, only one file may have a main() function, and the file with the main() must be in the file with the name specified for the problem. If you wish to submit multiple files, simply add their names to the end of your try command.
- Do not use any Java packages other
than java.math, java.io
and java.util.Scanner. In particular, note the absence of
any data structures and algorithms from java.util in this
list! Likewise for C++, you may use iostream
and cmath but you may not use anything from the STL.
If you use C, math.h, stdio.h are ok,
the same goes for stdlib.h, as long as you do not use qsort() and bsearch().
If you are unsure about what is allowed, please ask.
- The default version of Java is version 1.8, but you need to
make sure that your code compiles on the CS machines.
- For C++ programs, try will simply compile your code
with g++ program.cpp (which is currently g++ version 5.4.0)
- Additionally, for all cases, the use of the try program
means that you will not be able to submit code that does not
have the correct file name, compile and run!
- All input will be from standard input and output to standard
output, as described in each assignment. In particular, the input/output
does not come from/go to a file! You must not provide
any prompting or print anything else on standard output. Note that
on Unix systems, you can redirect the contents of a file to appear
on standard input, such as java MyProg < inputfile
- Sample inputs and outputs will be provided, but these may not
test all important cases - you should test your code using your
own test cases!
- For most problems, maximum values for the input (the length of the
input set, and/or the values themselves) will be given. This should
give you some guidance as to the complexity of the algorithms we
expect, but do not hard-code these values (or any values based on this
information) into your programs. That is, your program should work in
theory for any values. For example, if we guarantee that n is at most 1000,
please do not assume that n is a constant. We give you the bound on n
simply to give you an idea what input sizes should run in reasonable time.
Your algorithm's running time should be independent of the bounds we state in the html specification of the input/output. (A bit more on this: in homeworks 1-6 we will provide a pdf description of the problem statements, and an html description of the input/output specifications and bounds. If in the pdf, as part of the problem statement, we say that, for example, the input consists only of values 1,2,3, you can (and probably will need to) rely on this to get the required running time. On the other hand, the bounds in the html descriptions are merely to help you with coding, to estimate the size of the needed data structures, time limits, and so on. Do not rely on these in the design of your algorithm.)
You do not have to check for the correctness of the input - it will always follow the described specification.
Write your programs neatly - imagine yourself grading your program and see if it is easy to read and understand.
Comment your programs reasonably: there is no need to comment lines like "i++" but do include
brief comments describing the main purpose of a specific block of lines (e.g.,
"// merging two sorted arrays" if implementing the merge function in MergeSort).
- Unless otherwise specified, for each coding problem you need to also submit: (1) pseudo code of your algorithm and a brief verbal description of how the code works, (2) analysis of its running time (state the running time using asymptotic notation and how you came up with it), and (3) argument of its correctness. You will write these by hand and submit them to your instructor prior to the homework deadline, or include them in a text or pdf file and upload it to a dedicated dropbox on MyCourses. If you are working with a partner, then the same partner that submits the code through
try should also upload the parts (1), (2), and (3) to MyCourses.