代做CS 6043 – Fall 2024 Homework 1代做Python程序

CS 6043  Fall 2024

Homework 1 solutions

1    Problem 1

All digits are now 0 . . . d - 1.  As in class, observe that every increment causes some number of (d - 1)-to-0 flips, as well as exactly one additional flip.

Set

Φ = # non-zero bits in counter

We then have

ci  = 1 + # (d-1)-to-zero flips

And

Φi - Φ(i - 1) ≤ 1 - # (d-1)-to-zero flips

So then

ˆ(c)i  = ci + Φi - Φ(i - 1) 2

So in fact, no matter the value of d, the amortized number of flips is at most d = O(1).  (The constant inside O(1) actuallys down with d, but O(1) is good enough.)

2    Problem 2

Say that at some point we have T.num = x, T.size = 4x for some large x, and then operation i is a T.pop.  In this case we do a rebuild, so after the rebuild we have T.num = x - 1 and T.size = 2T.num = 2(x - 1)

ci  = x

and

Φi-1  = 0

and

Φi  = 4(x - 1) - 2(x - 1) = 2(x - 1)

So

ˆ(c)i  = x + 2(x - 1) = 3x - 1,

which is very large when x is big, so this potential function does not work.

3    Problem 3

3.1    Part 1

Recall that if we do n increments then the number of bits used is Blog(n)...B0 . Recall that bit i is flipped n/2i  times.  Using aggregate analysis, we now have that the total time over n increments is

 

3.2    Part 2

Intuitively, for the accounting analysis, we want to add i$ to bit Bi  if that bit is a 1, so that this money can be used to pay for flipping bit Bi. In fact to make the algebra work out we need to add 2i$ to bit Bi.  Recall that Bi is always one or zero.

To capture the above intuition, we use the following potential function:

 

Recall that every increment finds the right 0-bit (say Bk ) and then flips Bk to 1 while flipping all of B0 . . . Bk-1  to 0.

Let’s focus on some increment j and let Bk  be the right-most 0-bit right before the increment. This means that we end up flipping all of B0 . . . Bk  so we have: We have:

 

and

 

where in both of the above equations we are using the standard summation

formula  We thus have

 

Multiplying out all the parentheses gives us

ˆ(c)j  =  .5k2  + 4.5k  2

We thus have ˆ(c)j  = f(k) for the function f(k) =  .5k2  + 4.5k 2.

Since  .5k2   grows asymptotically faster than 4.5k, the function f(k) is upper bounded by a constant.  More concretely, is not hard to show that f(k) ≤ 9 for k ≥ 0.  You can this either using basic caluclus to optimize the function (it is maximum when k = 4.5), or you can simply plot the function on a graphing calculator.

In other words, we always have ˆ(c)j  9 = O(1), so the amortized cost per flip is O(1).

4    Problem 4

Algorithm:

● Whenever T.num = T.size:  rebuild into new array of size T.size = 1.3 · T.num

● Whenever T.num ≤ T.size/1.5: rebuild into new arrayof size T.size = 1.3 · T.num

Use potential function

Φ(D) = 10 · |1.3T.num — T.size|

Analysis

 If no rebuild then ci  = 1 and Φ(Di )Φ(Di-1 ) is at most 10·1.3 = O(1), so ˆ(c)i  = O(1).

● note that AFTER every rebuild we have Φ(D) = 0, because rebuild always sets T.size = 1.3T.num after

● If append causes rebuild then:

 ci  = T.num + O(1)

–  Φ(Di ) — Φ(Di-1 ) = 0 — 10 · .3T.num = —3T.num

  So ˆ(c)i  = O(1) + T.num  3T.num < O(1).

● If pop causes rebuild then:

 ci  = T.num + O(1)

—   Φ(Di ) — Φ(Di-1 ) = 0 — 10 · .2T.num = —2T.num

5    Problem 5

Let Si  be the number of balls in bin i.  We then set

 

, where | · | is the absolute value function.

Consider any move step from some bin Bj   to some other bin  Bk .   As mentioned in the hint, before the move we have Sj  > n and Sk  < n, so it is easy to see that every move decreases Φ by exactly 2.

On the other hand, it is easy to check that

Φfinal  = 0

Finally, since |Si  — n| ≤ Si + n, we have

 

. Thus, the total number of moves is at most 2n2 /2 = n2 , as desired.


热门主题

课程名

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
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图