1. Homepage
  2. Programming
  3. CSC373 Algorithm Design, Analysis and Complexity F24: Divide and conquer, Dynamic Programming

CSC373 Algorithm Design, Analysis and Complexity F24: Divide and conquer, Dynamic Programming

Engage in a Conversation
TorontoCSC373Algorithm Design Analysis and ComplexityDynamic programmingBellman equationDivide and conquer algorithm

Guidelines: (read fully!!) CourseNana.COM

CSC373 F24: Assignment 1 CourseNana.COM

Due: September 30, by midnight CourseNana.COM

  • Your assignment solution must be submitted as a typed PDF document. Scanned handwritten solutions, solutions in any other format, or unreadable solutions will not be accepted or marked. You are encouraged to learn the LATEX typesetting system and use it to type your solution. See the course website for LATEX resources. CourseNana.COM

  • Your submission should be no more than 8 pages long, in a single-column US Letter or A4 page format, using at least 9 pt font and 1 inch margins. CourseNana.COM

  • To submit this assignment, use the MarkUs system, at URL https://markus.teach.cs.toronto. edu/ CourseNana.COM

  • This is a group assignment. This means that you can work on this assignment with at most one other student. You are strongly encouraged to work with a partner. Both partners in the group should work on and arrive at the solution together. Both partners receive the same mark on this assignment. CourseNana.COM

  • Work on all problems together. If one of you writes the solution to a (sub-)problem, then the other student should proof read it. Both members of a group are responsible for understanding all solutions to all problems in their submission. CourseNana.COM

  • You may not consult any other resources except: your partner; your class notes; your textbook and assigned readings. Consulting any other resource, or collaborating with students other than your group partner, is a violation of the academic integrity policy! CourseNana.COM

  • You may use any data structure, algorithm, or theorem previously studied in class, or in one of the prerequisites of this course, by just referring to it, and without describing it. This includes any algorithm, or theorem we covered in lecture, in a tutorial, or in any of the assigned readings. Be sure to give a precise reference for the data structure/algorithm/result you are using. CourseNana.COM

  • Unless stated otherwise, you should justify all your answers using rigorous arguments. Your solution will be marked based both on its completeness and correctness, and also on the clarity and precision of your explanation. CourseNana.COM

Question 1. (11 marks) CourseNana.COM

In this question you are given as input n intervals I1 = [a1,b1], ..., In = [an,bn] on the real line. Each intervals Ij is specified by the two numbers aj and bj. We assume that aj < bj for all j. We also assume that no two intervals share any of their endpoints, i.e., all the numbers a1,...,an,b1,...,bn are distinct. The intervals are given in two arrays A[1..n] and B[1..n] where A[j] = aj and B[j] = bj. CourseNana.COM

We will say that intervals Ij and Ik cross if Ij Ik ̸= but neither interval contains the other one. In other words, Ij and Ik cross if exactly one of the endpoints of Ik is contained in Ij. CourseNana.COM

Part a. (3 marks) CourseNana.COM

Suppose that there exists some number x so that aj < x for all j, and bj > x for all j. Give an algorithm running in worst case time complexity O(n log n) to compute the number of pairs j < k such that Ij and Ik cross. Justify your answer. CourseNana.COM

Hint: use one of the divide and conquer algorithms from class. CourseNana.COM

Part b. (8 marks) CourseNana.COM

Give a divide and conquer algorithm that computes the number of pairs j < k such that Ij and Ik cross, without making the assumption from the previous subquestion. Your algorithm should run in worst case time complexity O(n log2 n). Justify your answer. CourseNana.COM

Part c. (7 marks)
(Bonus question - Optional). Modify your algorithm so that it runs in worst case time complexity CourseNana.COM

O(n log n). Justify your answer.
Hint: Try to call any subroutine that takes time O(n log n) only once, rather than recursively. CourseNana.COM

Question 2. (19 marks) CourseNana.COM

In this question, you are tasked with deciding the locations for k grocery stores, to serve n houses on a street. Suppose we model the street as the interval from 0 to 1, and the locations of the houses are given as real numbers x1,...,xn [0,1]. You can assume that x1 < x2 ... < xn, i.e., the locations are sorted from left to right, and that they are given to you as an array x[1 . . n] where x[i] = xi. Each week, one of the people living in each house travels once to their closest grocery store to buy their groceries. Your goal is to compute the locations y1, . . . , yk [0, 1] of the k grocery stores that minimize the total distance each household travels every week, given x and k as input. CourseNana.COM

Part a. (4 marks)
Prove that if
k = 1, then the optimal location of the single grocery store is the median of x1, . . . , xn. I.e., CourseNana.COM

the total distance each household travels to the grocery store at location y |x1 y|+...+|xn y| CourseNana.COM

is minimized by choosing y to be the median of x1, . . . , xn. Here we define the median as follows: recalling that x1 < ... < xn are sorted, the median is x(n+1)/2. So, the median of x1 < x2 is x2, and the median of x1 < x2 < x3 is x2 as well. (This may not be how you have seen medians defined for n even; any of the standard definitions would work, but please stick to the one above.) CourseNana.COM

Hint: There are many ways to prove this. One possibility is to show that, for x1 . . . xn, |x1 y|+...+|xn y|≥|xn x1|+|xn1 x2|+...+|x(n+1)/2x(n+1)/2|, CourseNana.COM

and that the two sides of the inequality are equal when y is the median. CourseNana.COM

Part b. (5 marks) CourseNana.COM

For 1 i j n, let M[i,j] equal |xi y|+...+|xj y|, where y is the median of xi,...,xj. Give an algorithm that computes all values of M[i,j] for all 1 i j n in worst case time complexity O(n2) (i.e., constant time per pair of i and j). Justify your answer. CourseNana.COM

Part c. (6 marks)
Give an algorithm that computes the minimum total travel distance achievable with
k store locations. I.e., CourseNana.COM

you need to output the minimum of CourseNana.COM

kk
min|x1 yj|+...+min|xn yj| (1) CourseNana.COM

j=1 j=1 CourseNana.COM

over all choices of y1, . . . , yk [0, 1]. Your algorithm should run in worst case time complexity O(kn2). Use bottom-up dynamic programming, and be precise about your choice of subproblems, and the optimal substructure you are using, i.e., the recurrence (Bellman equation) satisfied by the subproblems, and its base cases. Give pseudocode for your algorithm, and justify your answers. CourseNana.COM

Hint: You can also equivalently write the objective (1) as
( ! !) CourseNana.COM

min min X |xi y1| +...+ min X |xi yk| , CourseNana.COM

X1 ,...,Xk y1 [0,1] CourseNana.COM

iX1 CourseNana.COM

yk [0,1] CourseNana.COM

iXk CourseNana.COM

where the first minimum is over all ways to partition x1, . . . , xn into disjoint subsets X1, . . . , Xk. In other words, rather than directly choosing the store locations y1, . . . , yk, we first choose the set of households Xj which will go to store j, and then we choose the location yj of the j-th store to minimize the total distance the households in Xj need to travel. CourseNana.COM

Part d. (4 marks) CourseNana.COM

Modify your algorithm from the previous problem to also output the choice of store locations y1, . . . , yk that minimizes the total distance travelled. Your algorithm should still run in worst case time complexity O(n2k). Justify your answer. CourseNana.COM

Question 3. (14 marks) CourseNana.COM

The Galactic Research Society (GRS) has decided to organize an interstellar expedition. The president insists that exactly k members, including herself, join the expedition, and all selected members are required to participate. CourseNana.COM

There are n GRS members, and they are organized in a strict hierarchical structure (i.e., a tree), with the president at the root. Every society member is represented as a node in the tree. Every member except the president has a supervisor (their parent in the tree), and members supervise at most two other members (their children in the tree). CourseNana.COM

The society’s HR office has determined a “tension coefficient” between each member and their supervisor. This is a real number, and represents the degree to which there is tension between the member and their supervisor: a large positive number means their relationship is quite tense and there is potential for conflict, and a negative number with large absolute value means they get along very well. CourseNana.COM

Your task is to use a dynamic programming algorithm to choose exactly k members to join the expedition such that the total tension is minimized. You can assume that k (1 k n) is given to you, and also that the GRS hierarchy is given to you as a rooted binary tree T = (V,E), and each edge e = (u,v) E of the tree is labeled by the tension coefficient te = tu,v. The total tension of a set S V of k GRS members equals the sum of the te for all e = (u, v) where u and v are both in S. I.e., we add up the tension coefficients over all pairs of a society member and their supervisor who are both selected for the expedition. CourseNana.COM

Part a. (7 marks) CourseNana.COM

Define the subproblem structure you are using, and specify a recurrence satisfied by each subproblem, as well as the base cases of the recurrence. The recurrence should allow you to compute the value of a subproblem quickly (certainly in polynomial time), assuming the values of “smaller” subproblems have already been computed. Justify the recurrence. CourseNana.COM

CourseNana.COM

Part b. (3 marks) CourseNana.COM

Using your recurrence from the previous question, give a dynamic programming algorithm to compute the smallest possible total tension of a set S of k GRS members that includes the president (root of the tree). Your algorithm should run in time polynomial in the total number of GRS members n. Give pseudocode for your algorithm, and analyze its worst case running time. CourseNana.COM

Part c. (4 marks)
Modify your algorithm from the previous subproblem to also output a set
S of k GRS members, including the president, that minimizes the total tension. Analyze the modified algorithm’s worst case running time. CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
Toronto代写,CSC373代写,Algorithm Design Analysis and Complexity代写,Dynamic programming代写,Bellman equation代写,Divide and conquer algorithm代写,Toronto代编,CSC373代编,Algorithm Design Analysis and Complexity代编,Dynamic programming代编,Bellman equation代编,Divide and conquer algorithm代编,Toronto代考,CSC373代考,Algorithm Design Analysis and Complexity代考,Dynamic programming代考,Bellman equation代考,Divide and conquer algorithm代考,Torontohelp,CSC373help,Algorithm Design Analysis and Complexityhelp,Dynamic programminghelp,Bellman equationhelp,Divide and conquer algorithmhelp,Toronto作业代写,CSC373作业代写,Algorithm Design Analysis and Complexity作业代写,Dynamic programming作业代写,Bellman equation作业代写,Divide and conquer algorithm作业代写,Toronto编程代写,CSC373编程代写,Algorithm Design Analysis and Complexity编程代写,Dynamic programming编程代写,Bellman equation编程代写,Divide and conquer algorithm编程代写,Torontoprogramming help,CSC373programming help,Algorithm Design Analysis and Complexityprogramming help,Dynamic programmingprogramming help,Bellman equationprogramming help,Divide and conquer algorithmprogramming help,Torontoassignment help,CSC373assignment help,Algorithm Design Analysis and Complexityassignment help,Dynamic programmingassignment help,Bellman equationassignment help,Divide and conquer algorithmassignment help,Torontosolution,CSC373solution,Algorithm Design Analysis and Complexitysolution,Dynamic programmingsolution,Bellman equationsolution,Divide and conquer algorithmsolution,