辅导案例-COMP3600/6466

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
COMP3600/6466-Algorithms Homework 2
1
COMP3600/6466 — Algorithms
Convenor: Hanna Kurniawati ([email protected])
E-mail: comp 3600 [email protected] OR [email protected]
Due: Monday, 30 September 2019 23:59 GMT+10
Homework 2 Notes:
• This assignment consists of two parts. In the second part, you need to write computer
programs. You should write your programs in C/C++/Java. No other programming
language is accepted. We will support only C++.
• This assignment comes with two scaffolding, main.cpp and rbbtree template.h, as well as
testcases. All can be downloaded from the class website.
• Please submit both the report and the source codes, following the format below, with
[studentID] replaced by your student ID, e.g., U1234567.
• – Please write your report in a single .pdf file, named A2[studentID].pdf .
• – Please name the source code that contains your main function for Part B Q2
to be A2[studentID].cpp (or the suitable extension)
• – Please zip your report and source codes (please exclude the object files and
executables) into a single file, named A2[studentID].zip .
• – Please submit the .zip file via Wattle. Please note that the maximum file size
you can upload is 200MB.
• – Please save your submission as draft (i.e., don’t hit the ”Submit For Grading”
button), so that you can re-upload it until the last minute. Once the grace period
is over, the last saved draft in wattle will automat- ically be locked as your
submission.
• You can submit a scanned copy of a handwritten report. However, the handwriting must
be neat enough for the teaching staff to read them. If we can’t read them, we will not
mark them and therefore, you will get a 0 mark for the report component. Our
preference is you type your report. This is a good time to learn how to use TeX/LaTeX.
• We provide 13 hours grace period. This means, there will be no penalty if you submit
before Tuesday, 1 October 2019 13:00 Canberra time. However, we will NOT accept
assignment submission beyond this time.
• Assignment marking:
• – The total mark you can get in this assignment is 50 points.
• – This assignment will contribute 15% to your overall mark.
• – This assignment is redeemable. However, we strongly suggest that you do
this assignment. The results of this assignment will help you understand how
much you have understood the materials.
• Discussion with your colleagues are allowed and encouraged. However, you still need to
work on the assign- ment on your own AND write the names you discussed this
assignment with.
• You are allowed to use materials from books, slides, etc. as reference. This means that
you still need to write the solution yourself and put a reference to the source. A
reference need to be a full citation and specific, e.g., T.H. Cormen, C.E. Leiserson, R.L.
Rivest, and C. Stein. Introduction to Algorithms 3rd Ed. MIT Press. 2009. Sec. 2.2.
COMP3600/6466-Algorithms Homework 2
2
[10 points] Part A.






[40 points] Part B.
Finding a parking spot during semester time is a big problem at UNA, and Mr ParkingPls is
determined to address this problem. To this end, he observes that the difficulty in finding a
parking spot is worst on a certain day of the week and a certain time on that day. He hypothesises
that the main culprit of the worst parking problem is that there is an extremely large number of
overlapping lecture sessions on that particular day and time. If this is true, he can recommend
that UNA either redistribute the lecture slots more evenly during the week or rent a nearby land
on the particular day and time each week to expand its parking capacity.
Of course first, Mr ParkingPls must test his hypothesis. To this end, he has obtained the schedule
of all lectures at UNA. Since all classes at UNA either starts or ends at the beginning of an hour or
half an hour, Mr ParkingPls simplifies the lecture sessions representation by creating a time
index for every half-hour between 06:00 and 20:00 (inclusive) within a week —that is, time-1
refers to Monday 06:00, time-2 refers to Monday 06:30, · · ·, time-145 refers to Friday 20:00—.
He then represents each lecture session as a half-open interval of time index, e.g., interval [3, 5)
means the lecture starts on Monday 07:00 end ends (at a negligible amount) before Monday
08:00. The question is now to find the time index with the most number of overlapping lecture
sessions. Now, since he has only limited knowledge about Algorithms, he asks your help.
Your tasks
Since Mr ParkingPls would like to use this work for other much larger projects where new
sessions can be added quite often, Mr ParkingPls would like to use Red-Black Tree and asked
your help. To help him, please:
(a) [10 pts] Design a suitable Red-Black Tree data structure for Mr ParkingPls’ problem. This
means that given a Red-Black Tree implementation as defined in [CLRS] ch. 13, how you would
use/augment/modify this underlying data structure for Mr ParkingPls problem. Hint: You might
want to read [CLRS] sec. 14.3 first (provided as additional resources to this assignment).
(b) [15 pts] Please provide an algorithm for finding the time index with the largest number of
overlapping lecture sessions in the red-black tree you designed. Please also provide the
Every student enrolled at UNA is given a locker to store their books. The
locker has a lock mechanism akin to a luggage lock with 3-digit password
lock (Fig. 1 shows an illustration). Suppose the password each lock is set
uniformly at random and independently from the other locks by the locker
administrator, and suppose this password cannot be changed. The
administrator will improve this lock mechanism once the number of
enrolled students at UNA is large enough that there’s more than 50%
chance that two UNA students have the same password lock. How many
enrolled students should UNA has before the administrator improve the
lock mechanism? Please explain your answer.
Figure 1: An illustration
of the luggage lock for
UNA’s students’ lockers.

COMP3600/6466-Algorithms Homework 2
3
correctness proof (using loop invariant) and the time complexity (with its derivation) of your
algorithms. You will get full mark if the time complexity of your algorithm is O(1) and at most 9
points if the time complexity of your algorithm is O(log n).
(c) [15 pts] Please implement the above solution such that the user can find the time index by
giving the command “A2[studentID] input file name” OR “java A2[studentID] input file name”
from the command prompt. The input format is described in the next section. We provide you
with a main.cpp and a scaf- folding for Red-Black Tree. If you use C/C++, you need to implement
the node insertion function and the algorithm you provided in 2c on top of the provided main
function and Red-Black Tree scaffolding. If you use java, you need to make sure that your java
program accepts the same input as the provided main.cpp . You also need to develop Red-Black
Tree yourself. If you choose this path, you might want to first check which operations of Red-
Black Tree you need for this assignment and implement only those operations. Note: You are not
allowed to use TreeMap or other Java Red-Black Tree library.
Program Marking: If your program compiles and runs, you will get 3 points. We will then run
your program on 6 test cases: 2 cases would have up to 5,000 sessions, 2 cases would have 5,001
– 500,000 sessions, and 2 cases would have 500,001 – 5,000,000 sessions. For each test case,
your program will be given a total of (log n + 0.01)sec CPU time to find a solution. This time limit
includes the time for reading the file, inserting the data to the red-black tree, finding the solution,
and printing the solution. The time limit will be rounded up to 2 decimal digit. You can assume
your program will have access to at most 12GB RAM. It will be run as a single thread process on a
computer with Intel i7 3.4GHz processor. For each test case that your program solves correctly
within the given time and memory limit, you will get 2 points. Examples of the test cases are
available in https://cs.anu.edu.au/courses/comp3600/a2-testCases.zip.
Input to the Program
The program will accept a single argument, which is the name of the input file. The input file contains N + 1
lines, where N is the number of lecture session intervals.
The first line consists of a single number, which is N.
Each line in the next N lines consists of three numbers, separated by a white space. The first number is the
session ID, the second number is starting time index, and the third number is the ending time index.
Example: 5
 1 96 101
 2 46 49
 3 76 77
 4 8 10
 5 4 10

Output of the Program
COMP3600/6466-Algorithms Homework 2
4
The program outputs two lines to the standard output stream (i.e., use cout if you use C++).
The first line contains two numbers, each separated by a white space. The first number is the time index
with the most number of overlapping lecture sessions. Let’s denote this time index as t. The second number
(denoted as K) is the number of lecture sessions that overlap with time index t.
The second line consists of K numbers, each separated by a white space. Each number in this line is the ID of
the session that overlaps with time index t.
Example output for the above input:
8 2
4 5


51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468