Sie sind auf Seite 1von 2

CS 331: Algorithms and Complexity (Fall 2015)

Unique numbers: 50690, 50695, 50700, 50705, 50710, 50715


Assignment 4
Due on Friday, October 16th , by 11.59pm

Problem 1
(a) (10 points) You are given the following recurrences.
T1 (n) = 6T1 (n/4) + n2
T2 (n) = 4T2 (n/2) + n2

T3 (n) = nT3 ( n) + n, n 2
i Solve them using Master theorem or recursion tree to produce explicit forms for each.
Show your work.
ii Sort them in increasing order of growth rate for sufficiently large n.
(b) (5 points) A student came up with a sorting algorithm, S, the running time of which
is described by the following recurrence T1 (n) = 7T1 (n/2) + n2 . A competing student came
up with another algorithm, S 0 . The running time of the algorithm S 0 is described by the
recurrence T2 (n) = aT2 (n/4) + n2 . At what value of a do the two algorithms have the same
growth rate? Show your work.

Assignment 4

Problem 1 (continued)

Problem 2
(15 points) Consider a modified mergesort algorithm so that it splits the input not into
two sets of almost-equal sizes, but into three sets of sizes approximately one-third. You have
to do the following.
1. (5 points) Describe this ternary sorting algorithm including both the process of dividing
and combining.
2. (3 points) When combining three sets of sizes one-third each to form a set of size n,
what is the worst case number of comparisons that your algorithm makes in terms n.
Show your work.
3. (3 points) Write down the recurrence for this algorithm. (you can assume that T (1) = 1
and N is a power of 3.) Justify your answer.
4. (4 points) Find the asymptotic complexity of this algorithm. Show your work.

Problem 3
(10 points) A company is considering installing new wireless routers in their complex. The
plan is to install the n routers in a straight line along the main street that crosses the
complex. The locations for the n routers and the distances of these locations from the start
of the main street, are in feet and in increasing order, d1 , d2 , . . . , dn . The installation process
should proceed under two constraints:
At each location, the company can install at most one router. The expected number
of users for the router at location i is pi , where pi > 0 for i = 1, 2, . . . , n.
Any two routers should be at least m feet apart, where m is a positive integer.
You are asked to provide a Dynamic Programming solution to the problem of maximizing
the number of users for the routers subject to the above constraints. You have to do the
following.
1. (4 points) Identify the recurrence equation that expresses the maximum number of
expected users at location i. Justify your answer.
2. (6 points) Write the pseudo code of an iterative algorithm that builds up solutions
to larger and larger subproblems. You have to show the time complexity of your
algorithm.
3. (2 points - extra credit) Prove the correctness of your algorithm.

Page 2 of 2

Das könnte Ihnen auch gefallen