Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

csc263, fall 2022, problem set 2

You may work in a group of up to 2 students (i.e. you may work with up to 1 other students in the course, from any section).  For each question indicate the name of the (main) author and the proofreader.  Each of these roles, of course, gets the same credit.

Your solutions must be typed using a word processing tool such as Google Documents, MS Word, or LATEX, and produce a PDF document ps1.pdf, which you submit to Markus at https://markus.teach.cs. toronto.edu/2022-09/courses. Handwritten, then scanned, submissions will receive a grade of zero.

Any proofs you devise must be clear to the reader, without expecting them to ll in details in your steps. In particular, any proof by induction must make clear:  where you establish your base case(s), where you assume your inductive hypothesis, any bounds on variables, and where you use your inductive hypothesis and those bounds.

1.  Read function split in split .py. You may assume that its post-condition follows from its precondition, when it is called. You may also assume that its worst case run-time complexity is (n), where ❥A❥ = n. Now read function ith_element.

(a)  Prove that ith_elements post-condition follows from its precondition when it is run.

(b)  Prove that there is at least 50% probability that if split is called on array A with n elements, both A[0 : less] and A[more :] have no more than 3n=4 elements.

(c)  Use part (b) to prove that the expected number of calls to split until ith_element is called on an array of no more than 3n=4 elements is no more than a constant with respect to n.  Hint:   The notion of Bernoulli trials is helpful here.

(d)  Use (c) to form a recurrence for the expected run-time, T(n), of ith_element on an array of size

n. Then use the Master Theorem to deduce the asymptotic expected run-time class.

2.  GutSend (aka GS) contracts drivers to pickup and deliver fast food orders. They want you to produce software to keep track of the details. They need you to design:

GS-add(new-driver):  Add a new driver with an initially empty list of deliveries to GS’s contractors. Return a unique identifier driver-ID

GS-schedule(order-ID, current-time):  Add  order-ID  and the  current-time  (the time GS-schedule is executed) to the list of deliveries for the driver with a shortest list.  If there are two or more drivers with a shortest list, arbitrarily add the order to one of them.  Return the driver-ID of the driver contracted to deliver this order.

GS-next(driver-ID):  Remove the order with the earliest current-time recorded from driver-ID’s list. Again, for ties arbitrarily choose one. Return the removed order’s order-ID.

GS-order(order-ID):  Return what to pick up, from where, and where to deliver it.

GS-quit(driver-ID):  Apparently driver driver-ID has gotten disgusted by having no employee rights under Ontario labour law, and has quit.  Merge driver-ID’s list with those of another driver with a shortest list of deliveries, other than driver-ID. Return the merged driver’s driver-ID or "fail" if there is no such driver.

Use procedures from lecture, or CLRS readings, to implement these GS procedures. There is no need to provide code or pseudocode for procedures that have been given in CLRS or lecture, except when you modify some part of them.

GS would like the following worst-case run-time characteristics:

GS-add:  If there are m drivers, ❖(lg m).

GS-schedule:  If there are m drivers, and a shortest list has orders, ❖(lg m♥).

GS-next:  If driver driver-ID has orders, ❖(lg ♥).

GS-order:  ❖(1).

GS-quit:  If driver-ID has ♥1 orders, there are m drivers on the list after driver-ID quits, the shortest list after driver-ID quits has ♥2 orders, and ♥3 = max(♥1 ❀♥2), then ❖(lg m♥3).

3.  L = [① 1 ❀①2 ❀ . . . ❀①] is a list of items, each with a distinct priority, i.e.  ①i .p has priority p.  We want a bound on the worst-case run-time complexity of inserting the items from L into a binomial heap, using the procedure Binomial-Heap-Insert from the Binomial Heap notes on week of our home page. Compute the bounds using:

(a)  The aggregate method from CLRS. Show your work.

(b)  The accounting method from CLRS. Show your work.