![]() |
ANU College of Engineering and Computer Science
School of Computer Science
|
|
|
COMP2300, COMP6300Semester 1, 2009: Assignment 1
Deadline: 09:00 on Tuesday 31 March
(Please report any errors, mistakes and ambiguities to the course lecturer)
This assignment is worth 12% of your total course mark. It will be marked out of 48 as indicated below. The estimated time we expect you to spend on this assignment is around 12 hours in total (1 hour per 4 assignment marks).
SubmissionThis assignment must be submitted electronically. This can be done using the submit comp2300 ass1 ... command. (or the submit comp6300 ass1 ... command, if you have a COMP6300 enrollment).You should submit a separate file for each part of the assignment you are required to complete. The file names which you should use (and the only ones that will be accepted by the submit command) are:
fun.txt As an example of what you should do submit comp2300 ass1 shuffle.cAll files submitted must include, at the beginning, a completed preamble. The proforma for this can be found in the files: /dept/dcs/comp2300/public/standard_preamble.txt You have to copy the preamble from this files into the top of each file you intend to submit, and then complete your details. By submitting a file containing a completed preamble, you are making a declaration about the work you have submitted (see the text of the declaration in the preamble files. If you need to modify the text, e.g. you did in fact receive substantial assistance from another student, you should modify the text to say so). Any file submitted without a completed preamble will be rejected without being marked. Note you can submit any file multiple times, including after the deadline has expired. Note that if you submit any file after the deadline your entire submission will be considered as late and will attract a late penalty. ExtensionsSee http://cs.anu.edu.au/student/comp2300/assessment.php.Late PenaltiesLate penalties are as follows
PlagiarismSee http://cs.anu.edu.au/student/comp2300/assessment.php.
Part 1 - Fundamental Concepts [18 marks]Please show enough working to demonstrate how each answer is derived. Failure to do so may result in you being awarded partial or no marks for the question concerned (i.e. writing only the correct answer will give you NO marks). See the sample answers for Tute/Lab 01 as a guideline. Submit your answers as plain text in a file called fun.txt (make sure you have the completed preamble at the beginning).
Part 2 - Simple C Programming [16 marks](*** minor corrections/additions 24/03 ***) Over this course, we will study the algorithm which shuffle a vector (array of integers). This is a relatively simple algorithm but cam show interesting behavior when executed on a modern computer with a memory hierarchy, which we will investigate in future assignments. Furthermore, shuffle operations are used in algorithms such as the Fast Fourier Transform and bitonic sorting. Shuffles are also a kind of permutation and have some interesting mathematical properties. A 2-way shuffle of a deck of cards involves cutting the deck into 2 (even) `cuts' and interleaving cards in the the top (perfectly) with those in the second. In the out-shuffle, this is done in a way so that the top card of the top cut remains on the top, and the bottom card of the bottom cut remains on the bottom. This is illustrated nicely in Wikipedia. On a computer, the deck can be represented by an integer array. Furthermore, this can be generalized to a k-way out-shuffle, where the array is split into k even cuts, consecutively numbered as 0, 1, 2, ..., k-1. The shuffled array is produced by taking the remaining top elements of each cut, in a round-robin order cycling over cuts 0, 1, 2, ..., k-1, and placing these, in order, into the shuffled array. For example, for k=4, n=16, and an original array of:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
the cuts are at indices 0, 4, 8 and 12. Hence,
the shuffled array would be:
0 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15
Without loss of generality, we can make the restriction 1 ≤ k ≤ n (for k > n, the shuffle is an identity operation). For the moment, we will also assume that n is a multiple of k, for the sake of simplicity. The program shuffle.c will be the first and simplest prototype (indeed, simple enough to translate into PeANUt assembler, which you will do in Assignment 2). It will use basic control structures, a simple function with parameters, simple arrays, and I/O via printf() and scanf(). The program:
The printing of the array should be performed in a separate function (with the array address and n passed as parameters). Otherwise there are no constraints on how you implement the above steps, except that your program's output should match exactly that produced by the reference version of the program /dept/dcs/comp2300/public/ass1/shuffle. i.e. this program tells you the exact output messages etc that your program should produce. The command:
By running the reference program followed by your own after each other in a command tool, it should be possible to spot most errors in formatting. You cando a final check for correctness with the aid of the Unix sdiff utility:
echo "16 4" | /dept/dcs/comp2300/public/ass1/shuffle > out2 sdiff -s out1 out2 Note that you should remove any trailing spaces from output messages ( you could check for these by loading out1 into a text editor, and moving the cursor to the end of each line), and do not use tabs. Closer to submission time, you may also use the previewAutoMark ass1 command to check your output format. Note that this will only test your program on a sample of the tests that will be used in the actual marking. Your program should be written with good programming style (and so should not produce any warnings when compiled with the -Wall option!). I.e. it should be well commented, so as to enable the reader (this includes the tutor/marker!) to understand how it works. In particular, all functions (including main() should have a comment explaining what the function performs, as should all significant variables. Identifiers should be meaningful (e.g. MAX_SIZE rather than M), any constants should be named rather than hard-coded, and you are encouraged to use a coding style similar to that displayed in the examples given in lectures. Your program must compile and run correctly on the default gcc in DCS Linux Labs (use partch.anu.edu.au for remote access). Note that your program will be automatically compiled and run using various test cases. The ability of your program to reproduce the required behavior will contribute to about 50% to your marks. The remaining 50% of the marks will be awarded based on inspection of your code (completeness, coding style). As you will be translating shuffle.c into PeANUt in Assignment 2, keep it simple! That refers particularly to program structure (especially functions are hard to implement in assembler) and the use of external library calls - there will only be limited forms of printf() and scanf() available in PeANUt. Finally, if you have trouble getting the shuffle correct for arbitrary values of k, try to concentrate on 2 or powers of 2, as these are the most important! Part 3 - More Advanced C Programming [14 marks]COMP2300 VersionThe above program only performs a shuffle on an array of limited size. Given our aim of studying the memory hierarchy behavior of the shuffle computation, we will need to extend it to perform shuffles on very large arrays. However, it does not make sense to always print out the array if it is very large. When we do print it, it can be useful to be able to specify the number of elements to be displayed in each row of output. When we do not print the result, we should have some way of (at least partially) checking that the shuffle was performed correctly. This requires in turn a number of changes to be made.
Implementing this program will extend your C abilities in manipulating strings (and arrays of strings), command line parameters and ther exit status, the assert statement, dynamically allocated memory, and more complex control structures. You should only proceed with this part if your program shuffle.c is working satisfactorily. None or very few marks will be allocated for this part if it is not!. You may use your code from shuffle.c as a starting point for shuffle2.c. The program:
Similarly to before, your program's output should match exactly that produced by the reference version of the program /dept/dcs/comp2300/public/ass1/shuffle2. Thus, running this program can be used to determine the exact format of output messages etc. The reference version can also be used to resolve any ambiguity (but not inconsistency! - contact the lecturer if you think you find one) in the above specification.
Coding style and marking requirements for this part are as per Part 2. It is permissible to use global variables to record the values of command line parameters. Hints:
COMP6300 VersionCOMP6300 students should implement the COMP2300 version above, but getting the case n % k != 0 working is mandatory in the sense that it is worth 2 compulsory marks, rather than a bonus mark.
Last modified: 26/03/2009, 11:52
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Please direct all enquiries to:
Page authorised by: Head of Department, DCS |
| The Australian National University — CRICOS Provider Number 00120C |