代写CSC263H Data Structures and Analysis 2024 Homework Assignment #3代做留学生Matlab程序

Computer Science CSC263H

September 25, 2024

Homework Assignment #3

Due: October 9, 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 5 pages long in a 11pt font.

Question 1. (20 marks)   A real estate agency maintains information about a set of houses for sale.  For each house it maintains a record (p,s), where p is the price and s is the floor area of the house.   Each record of this type is called a listing.  You must design a data structure  D of listings that supports the following operations:

Insert(D, x):   If x is a pointer to a new listing, insert the listing pointed to by x into D.

•  Delete(D, x):   If x is a pointer to a listing in D, remove that listing from D.

•  MaxArea(D, p):   Return the maximum floor area of listings whose price is at most p.  If no listing has price at most p, then return −1.

The worst-case run time of each of the above operation should be O(log n) where n is the current number of listings in the data structure D.

In this question, you must describe how to implement the above using an augmented AVL tree T.  Since this implementation is based on a data structure and algorithms described in class and in the AVL handout, your should focus on describing the extensions and modifications needed here.

a. Give a precise and full description of your data structure.  In particular, specify:

what are the fields contained in each node of your AVL tree,

what is the key field, and

• what is (are) the augmented field(s), and what identity should this (these) field(s) satisfy at each node. Illustrate this data structure by giving an example of it (with a small set of your own choice).

b. Describe the algorithm that implements each one of the three operations above,  and explain why each one takes  O(log n) time in the worst-case.   For  Insert(D, x) and Delete(D, x), your  algorithm descriptions should be in clear and concise English. For MaxArea(D, p), you should give the pseudo-code.

Question 2. (20 marks)   A Scheduler S consists of a set of threads; each thread is a tuple t = (id,status) where id is a distinct positive integer and status ∈ {A,R, S}; intuitively, A means active, R means ready to be scheduled, and S means stalled. The operations that Scheduler S supports are:

NewThread(t): Given a thread t = (id,status), add thread t to S. You can assume that the id of t is

different from the id of any thread currently in S (so that all the threads in S have distinct ids). Find(i): If S has a thread t = (i,−) then return t, else return −1.

Completed(i): If S has a thread t = (i,−) then remove t from S, else return −1.

ChangeStatus(i,stat): If S has a thread t = (i,−) then set the status of t to stat, else return −1.

ScheduleNext:  Find the thread t with smallest id among all the threads whose status is R in S, set

the status of t to A and return t; if S does not have a thread whose status is R then return −1.

Describe how to implement the Scheduler S described above using an  augmented  AVL  tree  such  that each operation takes O(log n) time in the worst-case, where n is the number of threads in S.  Since this implementation is based on a data structure and algorithms described in class and in the AVL handout, you should focus on describing the extensions and modifications needed here.

a. Give a precise and full description of your data structure.  In particular, specify:

what are the fields contained in each node of your AVL tree,

what is the key field, and

what is (are) the augmented field(s), and what identity should this (these) field(s) satisfy at each node.

b. Describe the algorithm that implements each one of the five operations above, and explain why each one takes O(log n) time in the worst-case. Your description and explanation should be in clear and concise English. For the operations ChangeStatus(i,stat) and ScheduleNext, you should give the algorithm’s high-level pseudocode.

Question 3. (20 marks)   You are given a list L of n, not necessarily distinct, integers.  Your task is to devise an algorithm that outputs a list of the distinct integers in L, in order of non-increasing frequency (the frequency of an element in L is the number of times it occurs in L).  For example, if L is 2, 5, 4, 4, 2, 3, 4, 3, then a suitable output is 4, 3, 2, 5; the only other suitable output for this list is 4 , 2, 3, 5.

The expected running time of your algorithm should be O(n), under some assumptions discussed in class. Note: Do not assume that the integers in L are small, or they have a small range: they could be arbitrary. So a solution based on a direct access table or on linear time sorting is not acceptable.

a. Describe your algorithm in clear and precise English.

b. Explain why the expected running time of your algorithm is O(n).  Explicitly state every assumption that you need for your complexity analysis.

c. What is the worst-case running time of your algorithm? Use the Θ notation and justify your answer.

Hint: Use hashing with chaining, and find away to sort n numbers in the range 0 to nin O(n) worst-case time.

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

Question 4. (0 marks)

In this question, you must use the insertion and deletion algorithms as described in the “Balanced Search Trees: AVL trees” course note posted on Quercus.

a. Insert keys  17, 7, 8,  14,  19, 6, 10, 21, 15, 12, 9, 11 (in this order) into an initially empty AVL tree, and show the resulting AVL tree T, including the balance factor of each node.

b. Delete key 17 from the above AVL tree T, and show the resulting AVL tree, including the balance factor of each node.

In each of the above questions, only the final tree should be shown.

Question 5. (0 marks)   Consider an abstract data type that consists of a set  S of integers on which the following operations can be performed:

Add(i)  : Adds the integer i to S. If this integer already is in S, then S does not change.

Average(t)  :  Returns the average of all elements of S that are smaller than or equal to the integer t. If all the elements of S are larger than t, then return 0.

Describe how to implement this abstract data type using an augmented AVL tree T.  Each operation should run in O(log n) worst-case time, where n = |S| .  Since this implementation is based on a data structure and algorithms described in class and in the AVL handout, you should focus on describing the extensions and modifications needed here.

a. Give a precise and full description of your data structure.  In particular, specify:

what are the fields contained in each node of your AVL tree,

what is the key field, and

• what is (are) the augmented field(s), and what identity should this (these) fields satisfy at each node. Illustrate this data structure by giving an example of it (with a small set of your own choice).

b. Describe the algorithm that implements each one of the two operations above in clear and concise English. For the operation Average, you should also give the algorithm’s high-level pseudocode.  Explain why each operation takes O(log n) time in the worst-case.

Question 6. (0 marks)   Give an algorithm for the following problem.  The input to the algorithm are two unsorted sequences X  =  {x1 , x2 ,..., xn} and Y  =  {y1 , y2 ,..., yn} of n distinct positive integers each,  and a positive number d.   The  algorithm should determine whether there is  an xi   ∈ X  and  an yj  ∈ Y such that if we walk horizontally east for distance xi  and then walk vertically north for distance yj , we end up distance d from where we started:  if it is possible then the algorithm should output YES”, otherwise it should output “NO” .

The expected running time of your algorithm should be O(n), under some assumptions discussed in class. Note: Do not assume that the input numbers are small, or they have a small range:  they could be arbitrary. So a solution based on a direct access table or on linear time sorting is not acceptable.

a. Describe your algorithm in clear and precise English, and then give the pseudo-code.

b. Explain why the expected running time of your algorithm is O(n).  Explicitly state every assumption that you need for your complexity analysis.

c. What is the worst-case running time of your algorithm? Use the Θ notation and justify your answer. Hint: What data structures or algorithms that we learned in class involve reasoning about probability?


热门主题

课程名

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