首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导comp2123语言、讲解Python,Java程序设计、c++编程调试 解析C/C++编程|辅导Python编程
项目预算:
开发周期:
发布时间:
要求地区:
comp2123 Assignment 5 s1 2021
This assignment is due on May 27 and should be submitted on Gradescope. All
submitted work must be done individually without consulting someone else’s solutions
in accordance with the University’s “Academic Dishonesty and Plagiarism”
policies.
As a first step go to the last page and read the section: Advice on how to do the
assignment.
Problem 1. (10 points)
We are given a rooted tree T = (V, E) and its root u, i.e., a simple connected undirected
acyclic graph and a vertex u of this tree that we consider to be its root. We
want to compute the smallest set of vertices S ⊆ V such that every edge in E is
incident to some vertex in S.
Example:
u
v
w x
Vertex u is the root of the above tree. If we choose S = {v}, we indeed have the
property that every edge is incident to a vertex in S. Furthermore, there’s no smaller
set with this property. Picking S = {u, w, x} would also yield a set where every edge
is incident to a vertex in S, but it isn’t the smallest set. Picking S = {u, w} would
mean that edge (v, x) isn’t incident to any vertex in S.
We are given two algorithms for this problem:
degreeAlgorithm sorts the vertices of T by their degree and adds a vertex to S
if it’s incident to some edge that isn’t incident to any vertex in S.
BFSAlgorithm runs a breadth first search from the root u. Then it compares the
size of the union of all vertices in even layers to the size of the union of all vertices
in odd layers and returns the smaller of the two sets.
1: function degreeAlgorithm(M)
2: S ← ∅
3: Sort vertices in T by their degree and rename such that deg(v1) ≥ deg(v2)
≥ ... ≥ deg(vn)
4: for each vi
in T do
5: if vi
is incident to some edge e
6: and e isn’t incident to any vertex in S then
7: S ← S ∪ {vi}
8: return S
1
comp2123 Assignment 5 s1 2021
1: function BFSAlgorithm(T, u)
2: layers, parent ← BFS(T, u)
3: even ← the union of all vertices in layers[i], where i is even
4: odd ← the union of all vertices in layers[i], where i is odd
5: if |even| < |odd| then
6: return even
7: else
8: return odd
Argue whether degreeAlgorithm always returns the correct answer by either
arguing its correctness (if you think it’s correct) or by providing a counterexample
(if you think it’s incorrect).
a)
Argue whether BFSAlgorithm always returns the correct answer by either
arguing its correctness (if you think it’s correct) or by providing a counterexample
(if you think it’s incorrect).
b)
Problem 2. (25 points)
Our publishing company has accepted contracts to publish a set of n books B. For
each book bi
(0 ≤ i < n) we know the number of copies ci
that we agreed to
print, the time pi
that printing a single copy of this book takes, and the deadline
di by which all copies of the book should be printed. All ci
, pi
, and di are positive
integers. We can start printing at time 0 and all deadlines are given relative to this,
i.e., if di = x this means that printing all copies of book bi should be completed by
time x.
As we’re a small printing company, we only have a single printing press, so we
can only work on printing one book at a time. We’re allowed to change which book
we’re printing after we completed a full copy (i.e., we can’t switch halfway into
printing a book). We’re worried that we agreed to publish too much and you’ve
been hired to develop an algorithm to decide if this is indeed the case (and we
might need to start apologising to our clients). In other words, you need to design
an algorithm that returns true if there is an order to print the copies of the books
such that all deadlines are met, and false otherwise.
Example:
ci pi di
b1 3 1 5
b2 1 9 18
b3 2 2 7
In this case we can indeed print all copies of all books, for example by first
printing 1 copy of b1, then 1 copy of b3, 2 more copies of b1, 1 more copy of b3, and
finally 1 copy of b2. When printing starts at time 0, the above schedule implies that
b1 finishes printing at time 5, b2 is done at time 16, and b3 is completed at time 7.
In other words all books are printed by their deadline and so our algorithm should
2
comp2123 Assignment 5 s1 2021
return true. If we were required to print more than 1 copy of b2, there would no
longer exist a way to print all books by their respective deadlines and thus our
algorithm should return false.
Your task is to give a greedy algorithm for this problem that runs in O(n log n)
time. Remember to:
a) Describe your algorithm in plain English.
b) Prove the correctness of your algorithm.
c) Analyze the time complexity of your algorithm.
Problem 3. (25 points)
We are given an array A of length n with the following property: the first k integers
occur in increasing sorted order, the next 2n/3 integers occur in decreasing sorted
order, and the final n/3 − k + 2 integers occur in increasing sorted order. Note that
the last integer of the increasing sequence is also the first integer of the decreasing
sequence (hence, k ≥ 1), and that the last integer of the decreasing sequence is also
the first integer of the second increasing sequence. You are asked to determine the
minimum and maximum integer stored in this array. For simplicity you can assume
that n is a multiple of 3 and all integers are distinct.
Example:
A = [4, 5, 2, −2, −3, 0]
The first increasing sequence is [4, 5], the decreasing sequence is [5, 2, −2, −3], and
the second increasing sequence is [−3, 0]. The minimum integer in the array is −3
and the maximum is 5.
Your task is to give a divide and conquer algorithm for this problem that runs
in O(log n) time. Remember to:
a) Describe your algorithm in plain English.
b) Prove the correctness of your algorithm.
c) Analyze the time complexity of your algorithm.
3
comp2123 Assignment 5 s1 2021
Advice on how to do the assignment
• Assignments should be typed and submitted as pdf (no handwriting).
• Start by typing your student ID at the top of the first page of your submission.
Do not type your name.
• Submit only your answers to the questions. Do not copy the questions.
• When designing an algorithm or data structure, it might help you (and us)
if you briefly describe your general idea, and after that you might want to
develop and elaborate on details. If we don’t see/understand your general
idea, we cannot give you points for it.
• Be careful with giving multiple or alternative answers. If you give multiple
answers, then we will give you marks only for "your worst answer", as this
indicates how well you understood the question.
• Some of the questions are very easy (with the help of the lecture notes or
book). You can use the material presented in the lecture or book without proving
it. You do not need to write more than necessary (see comment above).
• When giving answers to questions, always prove/explain/motivate your answers.
• When giving an algorithm as an answer, the algorithm does not have to be
given as (pseudo-)code.
• If you do give (pseudo-)code, then you still have to explain your code and
your ideas in plain English.
• Unless otherwise stated, we always ask about worst-case analysis, worst case
running times etc.
• As done in the lecture, and as it is typical for an algorithms course, we are
interested in the most efficient algorithms and data structures.
• If you use further resources (books, scientific papers, the internet,...) to formulate
your answers, then add references to your sources.
• If you refer to a result in a scientific paper or on the web you need to explain
the results to show that you understand the results, and how it was proven.
4
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
urba6006代写、java/c++编程语...
2024-12-26
代做program、代写python编程语...
2024-12-26
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!