Professional Documents
Culture Documents
ExamFormat
MultipleChoice:10marks
ShortAnswer:45marks
ProgrammingQuestions:45marks
Pastpapersandpastsampleexams
ExamTipsandFeedbackfromPractests
Forthefinalexamyoumustbefamiliarwiththeassignment2specandbe
abletostateexactlywhichverticesadetectivewouldvisit,givenaparticular
mapifthedetectivewasfollowingaparticularstrategyetc.
Forprogrammingquestions:
Donotchangethestructswegiveyouunlessitsaysyoucaninthe
instructions
Donotfreethingswehavepassedintoyourfunctionsunlessittells
youto
Youwillnotgetmanymarksforcodethatdoesnotcompile.You
willmostlikelyget0.
Ifyouhavetimegobackandmakeupyourownteststothoroughly
testyourfunctionsyouwillbegiventhetestcodeinthefinalexam
sothiswillhelp.
Inthepracquiz2youhadtodiscusshowyoucoulddifferentiate
betweenparticularsortingalgorithms.
Youcan'tjustsaysomethinggenerallikeIwouldtimehowlong
differentdatasetstooktorunonthem.Whatdata?Whatdoesthat
showus?Bespecific.Forexample:ordereddatasetsofincreasing
size.Andthenyoumustexplainhowthathelpsusdifferentiate
betweenthespecificsortsinthequestion.
Donotsaythingslikemergesortisfasterorselectionsortisslower.
Usetheexacttimecomplexities.ForexampleBubblesortwithearly
exitisadaptiveandhasatimecomplexityofO(n)onordereddata,
whereasquicksorthasatimecomplexityofO(n^2)forordereddata
etc.
ExamContent
Notintheexam
Makefiles
ThingsyouwillNOThavetocodeintheexam
Note:thesearethingsyouneedtounderstand,youmayhavetotrace
throughorunderstandthetimecomplexityof,knowwhentouseetcbutwill
notbeaskedtowritethecodefor.Youshouldunderstandhowthecode
worksthoughtothoroughlyunderstandtheconcepts.Youcouldbegiven
thecodeforitandaskedtouseitforagivenproblem.
Shellsort
Splaytrees
Kruskal'salgorithm
Practest2
ExamFormat
1and1/2hours
4ProgrammingQuestionsworth10markseach.2Shortanswer
questionsworth5markseach
ExamContent
Contentuptoandincludingweek6lectures.
Possibleprogrammingquestions
programmingquestion/sonlinkedlists/sortinglinkedlists
programmingquestion/sonabinarysearchtrees
programmingquestion/songraphs
Shortanswerquestions
sorting
heaps
Practest1
ExamFormat
1and1/2hours
5ProgrammingQuestionsofequalweight
ExamContent
Thingsintheexam
programmingquestionsonlinkedlists
programmingquestionsonabinarysearchtrees
ExamInstructionsforPracTest1
Thepracexamconsistsoffivequestionsandyouhave1hourand30
minutestosolvethequestions.Eachquestionisworth10marks.
Asalways,itisagoodideatostartwiththesimplestquestionbemindful
ofthetime,ifyougetstuck,trytomovetothenextquestionandcomeback
totheproblemlater.
Thesubmissioninstructionsaredetailedinthefileforeachquestion.When
submittingyourprogram,thesystemwillrunacoupleofsimpletests.The
testcodeisnotavailable,butifatestfails,youcanusegdb,setabreak
pointatthefunctionyouimplemented,andstepthroughtheexecutiontosee
wherethingsaregoingwrong.
Eachquestionisdescribedinthecorresponding.cfile
ExamTipsforPracTest1
Donotmodifythe.hfiles.
Youmayalwayswriteadditionalstatichelperfunctionsinyourcfile.
Donotchangethestructswegiveyouunlessitsaysyoucaninthe
instructions
Donotfreethingswehavepassedintoyourfunctionsunlessittells
youto
Youwillnotgetmanymarksforcodethatdoesnotcompile
Youwillbegivena.ofilefortheteststhatwerunforsubmission.
Youwillnothaveaccesstothe.ctestfiles.Ifyouhavetimemakeup
yourownteststothoroughlytestyourfunctionsaswetestthings
morethoroughlywhenwemarkthem.
Resources
DuringtheexamyouwillhaveaccesstothefollowingReferenceCard(pdf)
Assignment 1 (COMP1927, 15x1): Textbuffers
Due: Monday 23:59:59 22nd December 2014
Your task is to implement an abstract textbuffer data type that meets the given
interface. In addition, you will have to write wrapper code to test your
implementation. Ensure that you also test for boundary conditions and for
memory management bugs.
You will submit the C code implementing the textbuffer ADT and your testing
code. Click here for the interface specification.
There is also a FAQ (frequenlty asked questions page) FAQ
Marking
The assignment is worth 10 marks. The marks breakdown is as follows:
Component
Marks
Autotesting of functionality
Testing Code
Style marks include marks for choosing an appropriate representation for your
ADT and for efficiency of the algorithms you choose. For example, you will
lose marks if your implementation of a function has work complexity of O(n^2)
when there is a solution with O(n) or O(n * log n).
Submission deadline
Unless otherwise stated if you wish to submit an assignment late, you may do
so, but a late penalty reducing the maximum available mark applies to every
late assignment. The maximum available mark is reduced by 10% each day it
is late and can be submitted a maximum of 5 days late. Assignment
extensions are only awarded for serious and unforeseeable events. Having
the flu for a few days, deleting your assignment by mistake, going on holiday,
work commitments, etc do not qualify. Therefore aim to complete your
assignments well before the due date in case of last minute illness, and make
regular backups of your work.
Submission details
To submit the assignment execute the following command on a CSE machine:
1927classrun15x1giveassn1textbuffer.c
testTextBuffer.c
You can check you submission with
1927classruncheck
The system permits you to submit multiple versions of your code. We will
grade the last submission. Please already submit partial solutions and submit
early. The system may be heavily loaded close to the deadline. We will not
grant special considerations for late submissions due to delays of
submissions close to the deadline.
Plagiarism
This is an individual assignment. Each student will have to develop their own
solution without help from other people. In particular, it is not permitted to
exchange code or pseudocode. You are not allowed to use code developed
by persons other than yourself. If you have questions about the assignment,
ask your tutor Before submitting any work you should read and understand
the following very useful guide by the Learning Centre How Not To Plagiarise.
All work submitted for assessment must be entirely your own work. We regard
unacknowledged copying of material, in whole or part, as an extremely
serious offence. For further information, see the Course Information.
Modifications and Clarifications
For the least turn paths for stage 3:
If there are 2 paths that would take equal turns and would result in the
agent having the same resulting stamina, either path is valid. (We will
not autotest this situation).
Also for the unit tests you hand in, we only want you using functions
from the original Graph.h, so it can compile with our version of
Graph.h.
The edges in the edges function should be in ascending order and not
contain duplicates.
Also you do not have to write unit tests for getVertexLabel as in the
original Graph.h there are no functions to actually set this information.
Assignment 2
Due: 23:59:59 Wednesday 11th February 2015
ASSIGNMENTS can not be submitted at all after Fri February 13th
2015 23:59:59
Marks: 13
Learning Objectives
Background
In this assignment you will control 4 detectives as they travel through a
network of cities trying to catch a thief. The aim of the detectives is for one of
the 4 detectives to catch the thief before he/she escapes to the getaway city
and before the time runs out. The aim of the thief is to reach the getaway
destination before time runs out and before being caught.
In our simulation, the detectives have a map of the city, but do not know
where the thief is or where he is trying to get to. The thief also has a map but
does not really know how to use it and wanders randomly through the cities
trying to reach the goal destination. The detectives employ different strategies
depending on what they have been assigned to.
Assignment 2 Files
Here are the files supplied for assignment 2. You can change into your
assignment 2 directory and run the following command:
cp
/home/cs1927/public_html/15x1/assignments/assn2/assn2
Files/*.
The provided files are:
1. Makefile: This controls compilation of the program. You only need to
modify this if you create additional files for your implementation.
It mustproduce and executable called assn2
2. Graph.h: Graph ADT Interface
This is a sample data file that represents the map of cities. The first line
shows how many cities are in the graph. Then for every city there will be a line
of data listing its edges with weights. This is an undirected graph, so if there is
an edge from 0 to 5 with weight 29 there should be an edge from 5 to 0 with a
weight 29. After the edges are listed each vertex will have data segment with
a value of either 'n' or 'i' and then its actual string representation. The 'n'
indicates that it is a normal city. The 'i' indicates the city has an informant
there.
100529141660750840nsydney1251529n
adelaide2nmelbourne3530436nperth43369
20ndarwin5129029330610nhobart6n
auckland7nmadrid8nnewyork9nbrisbane
Agents data
The first line of data represents information about the thief. The first number
represents the amount of stamina the thief starts with. The second number
indicates where the starting location of the thief is. The third number
represents the goal city of the thief. This is followed by a string representation
of the thief.
The next four lines represent the 4 detectives. Each detective is also given a
starting stamina and a starting location. However the third integer represents
the strategy that the detective is assigned. This is followed by a string
representation of the detective.
1056T120D1131D2512D3542D4
Command Line Arguments
The program requires 3 command line options with an optional fourth. The
command line arguments are as follows:
1. The name of the city data file
2. The name of the agent data file
3. The maximum number of cycles in the game
4. A random seed value
Assignment 3 Tasks
1. Task 0: Graph blackbox unit testing - 2 Marks
You must create a file called testGraph that tests the functions defined
in the given Graph.h file. You must create assert based tests. We will
run your testGraph.c code with our own working and broken graph
implementations to check they pass and fail the implementations
accordingly. You do not need assert based tests for the functions show
or destroyGraph.
You do not need to submit tests for any additional functions you add to
your graph when you complete the other tasks of the assignment.
2. Task 1: Assignment Diary - 1 Marks
You must maintain and design an implementation diary. As you
complete your work on this assignment you must maintain an
assignment diary where you will reflect on what you have done. In a
text file called assn2Diary.txt place the date and time of your work
together with some brief comments of the work you have completed
such as what you worked on, what you accomplished and what bugs
you fixed. You should discuss your choices of data structures and
additional ADTs you have used in your implementation. It should also
discuss how you have tested your implementation.
3. Task 2: Implementation
The implementation is divided into 4 stages as outlined below
1. Stage 0: RANDOM strategy - 2 automarks
For stage 0 we will test detectives using the random strategy
only. The random strategy has been implemented, however you
will need to modify the provided code in these ways to pass
stage 0:
same seed, you can produce the same ordering of 'random' moves and
repeat exactly the same situation.
Available Commands
Once the program has started the user will be prompted for input. The
available commands are listed below:
1. run
This will run an entire simulation, printing out a trace of the agents
location for each cycle of the game. It will print out how the game
finished ie with the thief being caught, getting away, time running out.
2. step
This command will run just one cycle of the game, printing out the new
location of the agents for the next cycle. If the game finished in that
cycle, it will also print out how the game finished. This allows the user
to step through the game one cycle at a time.
3. stats
This prints out statistics about the agent. This includes the name of the
agents' current location, the name of the agent's goal location if it is the
thief or was given the thief's location, and the agents' stamina.
4. display
This will display the current locations of all agents
5. map
This prints out the graph connectivity information that represents the
map of the city.
6. quit
Quits the game!
Stage 0:
In this example all detectives are following the RANDOM strategy (strategy 0).
The thief uses the random strategy.
./assn2citiesSmall.dataagentsS0.data106
POLICEACADEMY1927Redalert!Athiefisonthe
run.Agents,toyourcars.Youhave10hours.Hour0
TD1D2D3D431111Enter
command:mapV=4,E=301:4102:90010:41
20:90023:3032:30Entercommand:stats
Hour0T1000california(3)melbourne(0)D1100000
perth(1)D25000perth(1)D350perth(1)D4500
perth(1)Entercommand:stepHour1TD1D2D3
D420000Entercommand:statsHour1
T970darwin(2)melbourne(0)D199959melbourne(0)
D24959melbourne(0)D39melbourne(0)D4459
melbourne(0)Entercommand:stepHour2TD1D2
D3D431201Entercommand:stats
Hour2T940california(3)melbourne(0)D199918
perth(1)D24059darwin(2)D350melbourne(0)D4
418perth(1)Entercommand:displayHour2TD1
D2D3D431201Entercommand:run
Hour3TD1D2D3D420310Hour
4TD1D2D3D401211Tgot
awaytomelbourne(0)GAMEOVER:YOULOSETHIEFGOT
TOGETAWAY
Stage 1:
In this example all detectives are using the CHEAPEST_LEAST_VISITED
strategy and the thief is following the usual random strategy.
./assn2citiesMedium.dataagentsS1.data104
POLICEACADEMY1927Redalert!Athiefisonthe
run.Agents,toyourcars.Youhave10hours.Hour0
TD1D2D3D498762Enter
command:runHour1TD1D2D3D4400
51Hour2TD1D2D3D49550
5Hour3TD1D2D3D446686
Hour4TD1D2D3D435500Hour
5TD1D2D3D456118Hour6
TD1D2D3D416220Hour7T
D1D2D3D400117D1caughtthe
thiefinsydney(0)YOUWINTHIEFCAUGHT!
Stage 2:
In this example detectives 3 and 4 use the DFS strategy. In this strategy they
do a depth first traversal from their starting points and follow this at each
cycle. If they do not have the stamina to go to the next city on their route, they
remain at the same location to regain their stamina and continue on the set
path. (This happens even if there were other options they did have the
stamina for.) In this example detective 1 and 2 are sill following the
CHEAPEST_LEAST_VISITED strategy and the thief is of course using the
RANDOM strategy.
./assn2citiesMedium.dataagentsS2.data102
POLICEACADEMY1927Redalert!Athiefisonthe
run.Agents,toyourcars.Youhave10hours.Hour0
TD1D2D3D492812Enter
command:runHour1TD1D2D3D4410
01Hour2TD1D2D3D49555
0Hour3TD1D2D3D446630
Hour4TD1D2D3D495545Hour
5TD1D2D3D445193Hour6
TD1D2D3D440244D3caughtthe
thiefindarwin(4)YOUWINTHIEFCAUGHT!
Stage 3:
In this example detective D1 and D2 start with CHEAPEST LEAST_VISITED
strategy and detective 3 and 4 start with the DFS strategy. However detective
1 and 4 starts off in a city with an informant (this is indicated by the * character
on the display), so straight away switch to the strategy of going along the
shortest path to the thiefs currentLocation (city 9). Detective 4 reaches the
destination by hour 5 but the thief is no longer there. However the other
detectives have found the thief by this stage anyway. Detective 1 is following
the shortest path from 8 to 9, but has to stop at Hour 4 to regain stamina.
Detective 2 finds an informant in city 1 in hour 1 and goes via the shortest
path from vertex 1 to 4. In hour 3 detective 3 finds an informant and goes via
the shortest path to vertex 4.
So D1 calculated that the path that takes the least number of turns to get from
8 to 9 (taking into account his/her stamina) is 8,0,5,3 (rest) ,4,9 (cost 6 turns).
D1 calculates the path to be 8,0,5,3,4,9 so it costs 5 turns.
In Hour 1, D2 runs into an informant and calculates the path from 1 to 4. (1,5
(rest),3,4)
In Hour 3 D3 runs into an informant and calculates the path from 1 to 4.
./assn2citiesInformants.dataagentsS3.data202
POLICEACADEMY1927Redalert!Athiefisonthe
run.Agents,toyourcars.Youhave10hours.Hour0
TD1D2D3D498*268*Enter
command:runHour1TD1D2D3D4401*
00Hour2TD1D2D3D49550
5Hour3TD1D2D3D44351*3
Hour4TD1D2D3D493354Hour
5TD1D2D3D444439D1caught
thethiefindarwin(4)YOUWINTHIEFCAUGHT!
Assessment
Assignment 2 is worth 13 Marks. Your Assignment 2 submission will be
assessed in the following way:
Automarking of Stage 0: 2
Automarking of Stage 1: 2
Automarking of Stage 2: 2
Automarking of stage 3: 2
Assignment diary: 1
Programming style: 2
Program Failures
If the ~cs1927/bin/assn2Model program fails (e.g., segmentation fault, bus
error) or behaves incorrectly according to the specification, please email
angf@cse.unsw.edu.au and attach the test file or a description of the input
that caused the failure/bug.
Late Penalty
A late penalty of 10% per day applies to the maximum mark.
ASSIGNMENTS can not be submitted at all after Fri February 13th 2015
23:59:59
Originality of Work
ALL work submitted for this assignment MUST BE YOUR OWN WORK and it
MUST BE COMPLETED INDIVIDUALLY. DO NOT COPY FROM OTHERS;
DO NOT ALLOW ANYONE TO SEE YOUR CODE. We regard copying of
assignments, in whole or part, as a serious offence. We use plagiarism
detection software to search for multiply-submitted work and work that is
similar to programs found on the internet and other sources. Be warned that:
Submission
You need to submit your assignment using the give command on a CSE
machine
1927classrun15x1giveassn2*.c*.hassn2Diary.txt
Makefile
Assignment 2 Bonus: Master Thief
Due: 23:59:59 Thursday 12th February 2015 No Late Submissions accepted
Worth: 2 marks
Assignment 2 Bonus Challenge Tasks
1. Task 0: Makefile - 0 Marks (but mandatory - you will receive 0 for
automarking if it is missing)
Complete a Makefile for the bonus component of the assignment.
It should be capable of producing:
File name
Comment
assn2Bonus
Client program
Any other entries that can beat the Random Thief will be given a score
of 1
Any other serious attempts that do not beat the Random Thief will get
0.5
Originality of Work
ALL work submitted for this assignment MUST BE YOUR OWN WORK and it
MUST BE COMPLETED INDIVIDUALLY. DO NOT COPY FROM OTHERS;
DO NOT ALLOW ANYONE TO SEE YOUR CODE. We regard copying of
assignments, in whole or part, as a serious offence. We use plagiarism
detection software to search for multiply-submitted work and work that is
similar to programs found on the internet and other sources. Be warned that:
Submission
You need to submit your assignment using the give command on a CSE
machine
1927classrun15x1giveassn2Bonus*.c*.hMakefile
assn2BonusDiary.txt
Assessment
Deadline: 11:59pm Tue 9 December 2014
Total Marks: 3
You must get your tutor in your lab to mark the exercises during the allocated
lab time or the following week if you submitted your lab on time using give. Try
to get them to mark each exercise as you complete it in your lab time if
possible. In addition to the code that the exercise calls for, you will of course
have to write some additional code to test the correctness of your
implementation. Your tutor may want to see this testing code, too. Good style
requires good tests!
Exercise 1 - Linked Lists (0.5 mark)
Copy the files lists.h , lists.c and testLists.c into your working directory. The
file lists.ccontains a printList function and stubs for other functions you
need to implement to complete the lab. You can use testLists.cto write
your tests, but do not edit lists.h
Implement the function
intsumListItems(linkls);
which adds all the items in a list and returns the resulting integer value, and
and tests to testLists.c. Test it for lists with zero, one, and some more
elements.
Compile your program with the command
gccWallWerrorgotestListstestLists.c
lists.c
The g option makes sure that debug information is generated.
Execute your program in gdb or ddd and show your tutor that you can:
1. set a breakpoint at the beginning of a function and at a given line in the
program
2. know how to inspect the elements of a list using the print command
3. inspect the call stack.
Exercise 2 - Linked Lists (0.5 mark)
Type in the command
valgrind./testLists
The output should show you that you have some memory leaks - assuming
you have written some code in testLists that actually adds some nodes to your
linked list.
Implement the function
voidfreeList(linklist);
that frees all the memory for each node in your list. Once you have written the
function, test it in your testLists code. Run valgrind again and check that all
the memory leaks have gone. You must be able to show this to your tutor.
Exercise 3 - Linked Lists (1 mark)
Implement the function
linkfromTo(intstart,intend);
which creates a list with the elements start to end. If start is greater
than end, return the empty list. Examples:
fromTo(2,6)2>3>4>5>6>XfromTo(3,3)
3>XfromTo(4,3)>X
Exercise 4 - Doubly Linked Lists (1 mark)
Write a function
dlinkdoublify(linkls)
which, given a linked list, creates a new doubly linked list with the same items
as elements. You might want to write a printDList function to test it.
You must also write a function
voidfreeDList(dlinklist);
and make sure you can demonstrate that you have freed the memory
correctly to your tutor.
Submitting your lab
You must get the lab marked by your tutor in your lab. You should also submit
your solution using give on a CSE machine. To do this, run:
1927classrun15x1givelab01lists.c
Due Date: 11:59:59pm Wednesday 11/12/2013