0% found this document useful (0 votes)
47 views

COMPSCI330 Design and Analysis of Algorithms Assignment 1: Due Date: Thursday, August 27, 2020

This document provides guidelines and problems for Assignment 1 of the COMPSCI330 Design and Analysis of Algorithms course. It is due on August 27, 2020 and should be submitted to GradeScope. Problems include: [1] analyzing the running time of a recursive function, [2] designing algorithms to find values within a range in an array and approximate roots of a Lipschitz function, and [3] finding the weighted median of an array and location for an airport to minimize average travel time. Students should show the steps of their algorithms rather than just the final answers or code.

Uploaded by

Canji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

COMPSCI330 Design and Analysis of Algorithms Assignment 1: Due Date: Thursday, August 27, 2020

This document provides guidelines and problems for Assignment 1 of the COMPSCI330 Design and Analysis of Algorithms course. It is due on August 27, 2020 and should be submitted to GradeScope. Problems include: [1] analyzing the running time of a recursive function, [2] designing algorithms to find values within a range in an array and approximate roots of a Lipschitz function, and [3] finding the weighted median of an array and location for an airport to minimize average travel time. Students should show the steps of their algorithms rather than just the final answers or code.

Uploaded by

Canji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

COMPSCI330 Design and Analysis of Algorithms

Assignment 1

Due Date: Thursday, August 27, 2020

Guidelines
• Describing Algorithms If you are asked to provide an algorithm, you should clearly define
each step of the procedure, establish its correctness, and then analyze its overall running
time. There is no need to write pseudo-code; an unambiguous description of your algorithm
in plain text will suffice. If the running time of your algorithm is worse than the suggested
running time, you might receive partial credits.

• Typesetting and Submission Please submit the problems to GradeScope. You will be
asked to label your solution for individual problems. Failing to label your solution can
cost you 5% of the total points (2.5 points out of 50 for this homework).

• LATEX is preferred, but answers typed with other software and converted to pdf is also ac-
cepted. Please make sure you submit to the correct problem, and your file can be opened by
standard pdf reader. Handwritten answers or pdf files that cannot be opened will
not be graded.

• Timing Please start early. The problems are difficult and they can take hours to solve. The
time you spend on finding the proof can be much longer than the time to write. If you need
more time for your homework please submit a STINF request to Kate.

• Collaboration Policy Please check this page for the collaboration policy. You are not
allowed to discuss homework problems in groups of more than 3 students. Failure to adhere
to these guidelines will be promptly reported to the relevant authority without
exception.

1
Problem 1 (Recursion). (10 points) Please solve the following recursion (write the answer in
asymptotic notations T (n) = Θ(f (n))).
If you decide to use the recursion tree method, you do not need to draw the tree. Just describe
what the tree looks like in the second layer (e.g. there are a subproblems each with size n/b), bound
the amount of work in each layer, and take the sum over all layers. You do not need to write the
induction proof if you are using the recursion tree method.

T (n) = T (n/5) + T (4n/5) + n, T (1) = 0.

Problem 2 (Finding root). (20 points) Given an array a[1..n] of real numbers, suppose adjacent
entries are within a value of b, that is, |a[i]−a[i+1]| ≤ b for i = 1, 2, ..., n−1. Assume a[1] < 0 < a[n].
(a) (10 points) Design an algorithm that finds an index k such that |a[k]| ≤ b/2, prove its correctness
and analyze its running time. (Your algorithm should run in O(log n).)
(b) (10 points) A function f (x) is called Lipschitz if for any two values x and y, |f (x)−f (y)| ≤ |x−y|.
Given a Lipschitz function f (x) that satisfies f (0) < 0 < f (1), design an algorithm to find an -
approximate root of the equation f (x) = 0: that is, find a number x such that |f (x)| ≤ . Your
algorithm should run in O(log 1/) time.

Problem 3 (Weighted Median). (20 points) In class, we learned a linear time algorithm that
finds the median of an array of numbers. We now wish to solve a more general problem using
this algorithm. The input is an (unsorted) array of numbers x1 , x2 , . . . , xn , each with an P associated
positive weight (we denote the weight of xi by wi ) such that the sum of weights is 1 (i.e., ni=1 wi =
1). Suppose φ defines an ordering of indices such that xφ(1) , xφ(2) , . . . , xφ(n) is sorted. The weighted
median of the numbers is the value xφ(m) such that m−1
P Pm
i=1 wφ(i) < 0.5 and i=1 wφ(i) ≥ 0.5.

(a) (10 points) Give an algorithm that finds the weighted median of an array in O(n) time. You
may assume that you have an algorithm to find the median of an array (without weights) in
O(n) time (e.g., the algorithm you learned in class). This algorithm can be used as a “black
box” (like a function call) and need not be described in your solution. Remember that the
array is unsorted and sorting the array at any point during the algorithm will take Ω(n log n)
time.

(b) (10 points) Alice Algorithmix lives on a long, narrow island somewhere off the coast of North
Carolina where all the cities on the island are on a single straight line. The island government
has decided to build an airport that will serve all the cities and has asked Alice to come up
with a location that would minimize the average travel time to the airport for the residents
of the island. (The travel time of a resident is proportional to her distance from the airport.)
Can you help Alice solve the problem in O(n) time if there are n cities? You can assume that
Alice gives you the locations of the cities and their respective populations.

Hint: Problem (b) is related to problem (a). You can use an algorithm you designed for problem
(a) as a black box.

You might also like