代做CSC263H Data Structures and Analysis September 4, 2024 Homework Assignment #1

Computer Science CSC263H

September 4, 2024

Homework Assignment #1

Due: September 11, 2024, by 11:00 am

You must submit your assignment through the  Crowdmark system. You will receive by email an invitation through which you can submit your work. If you haven’t used Crowdmark before, give yourself plenty of time to figure it out!

You must submit a separate PDF document with for each question of the assignment.

To work with one or two partners, you and your partner(s) must form a group on Crowdmark (one submission only per group).  We allow groups of up  to  three students.  Submissions by groups of more than three students will not be graded.

The PDF file that you submit for each question must be typeset (not handwritten) and clearly legible. To this end, we encourage you to learn and use the LATEX typesetting system, which is designed to produce high-quality documents that contain mathematical notation. You can use other typesetting systems if you prefer, but handwritten documents are not accepted.

If this assignment is submitted by a group of two or three students, for each assignment question the PDF file that you submit should contain:

1. The name(s) of the student(s) who wrote the solution to this question, and

2. The name(s) of the student(s) who read this solution to verify its clarity and correctness.

By virtue of submitting this assignment you (and your partners, if you have any) acknowledge that you are aware of the homework collaboration policy for this course, as stated here .

•  For any question, you may use data structures and algorithms previously described in class, or in prerequisites of this course, without describing them. You may also use any result that we covered in class (in lectures or tutorials) by referring to it.

Unless we explicitly state otherwise, you should justify your answers. Your paper will be marked based on the correctness and efficiency of your answers, and the clarity, precision, and conciseness of your presentation.

The total length of your pdf submission should be no more than 3 pages long in a 11pt font.

Question 1. (20 marks)  The following procedure has an input array A[1..n] with n ≥ 2 arbitrary integers.

In the pseudo-code, “return” means immediately exit the procedure and then halt. Note that the indices of array A starts at 1.

weirdo(A[1..n])

1   n = A. size

2 for i = 1 to n                           // i = 1, 2, . . . , n

3 for j = 1 to n                    // j = 1, 2, . . . , n

4 if A[n - j + 1] j then return

5 if (A[i] n - i + 1) or (A[1] + A[2] = 2n - 1) then return

6 return

Assume that each assignment, comparison, and arithmetic operation takes constant time.

Let T(n) be the worst-case time complexity of calling weirdo(A[1..n]) on an array A of size n ≥ 2. Give a function f(n) such that T(n) is Θ(f(n)).

Justify your answer by explaining why it is O(f(n)), and why it is Ω(f(n)). Any answer without a sound and clear justification may receive no credit.

Question 2. (20 marks)

We want to compute the median of every prefix  of an  input array A[1..n] of arbitrary integers.   More precisely, design an algorithm that outputs another array M[1..n], so that M[i] is equal to the median of the integers in the subarray A[1..i]. Recall that when i is odd, the median of A[1..i] is the element of rank (i+1)/2 in the subarray, and when i is even, the median is the average of the elements with ranks i/2 and i/2 + 1. Your algorithm should run in worst-case time O(nlog n).

Hint: Maintain two heaps for the subarray A[1..i]:  one that contains「i/2l elements of this subarray, and one that contains  li/2」elements of this subarray. What elements of A[1..i] should each one of these heaps contain?  What kind of heap each one them is?  How do you use them to compute the median of A[1..i]? How do you maintain these heaps when you increase i to i + 1?

a. Describe your algorithm in clear and concise English, and also provide the corresponding pseudocode. Argue that your algorithm is correct.

b. Justify why your algorithm runs in time O(nlog n) in the worst case.

[The questions below will not be corrected/graded.  They are given here as interesting problems that use material that you learned in class.]

Question 3. (0 marks)   Design an efficient algorithm for the following problem.  The algorithm is given an integer m ≥ 1, and then a (possibly infinite) sequence of distinct integer keys are input to the algorithm, one at a time. A print operation input can also occur at any point between keys in the input sequence. When the algorithm gets a print operation input, it must print (in any order) the m smallest keys among all the keys that were input before this print.

For example, suppose m = 3, and the keys and print operations are successively input to the algorithm in the following order:

18, 13, 29, 4, 11, 22, print, 8, 15, 7, 14, 3, 9, 12, print, 2, 5, . . .

The first print should print 13, 4, 11 (in any order), and the second print should print 4, 7, 3 (in any order). Assume that:  (1) m does not change during an execution of the algorithm,  and  (2) at least m keys are  successively input to the algorithm before the algorithm gets its first print input.

Describe a simple algorithm that solves the above problem with the following worst-case time complexity:

•  O(log m) to process each key input.

O(m) to perform. each print operation.

Your algorithm must use a data structure that we learned in class.

•  State which data structure you are using and describe the items that it contains.

• Explain how your algorithm processes a key input, and how it processes a print operation input. First describe this clearly and concisely in English, and then give the pseudo code.

Explain why your algorithm achieves the required worst-case time complexity described above.

Prove that your algorithm is correct (Hint: use induction. What is your induction hypothesis?)

Question 4. (0 marks)   Let A be an array containing n integers.  Section 6.3 of our textbook  (CLRS) describes a procedure, called Build-Max-Heap(A), that transforms array A into a max-heap in O(n) time. That procedure works “bottom-up”, using Max-Heapify repeatedly.

Another way of transforming A into a max-heap is to insert the elements of A into the heap one at a time. Specifically, the algorithm is as follows:

Build-by-Inserts(A)

A.heapsize := 1

for i := 2..n do

Max-Heap-Insert(A, A[i])

a. Give an example of an input array A for which the two procedures Build-Max-Heap and Build- by-Inserts produce different outputs. Keep your example as small as possible.

b. Let T(n) be the worst-case time complexity of Build-by-Inserts for an input array A of size n. Prove that T(n) is Θ(nlog n).  (Recall that the worst-case time complexity of Build-Max-Heap is O(n), and therefore Build-Max-Heap is more efficient than Build-by-Inserts.)


热门主题

课程名

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
站长地图