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

h1 Cse548 Spring2012

This document contains the instructions for Assignment #1 of CSE 548 - Analysis of Algorithms taught by Michael A. Bender in Spring 2012. It lists 11 problems related to algorithm analysis and complexity. Students are asked to solve each problem on a separate sheet using LaTeX and submit their problem sets stapled together, indicating which solution they want graded. No late submissions will be accepted.

Uploaded by

stonethumb
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

h1 Cse548 Spring2012

This document contains the instructions for Assignment #1 of CSE 548 - Analysis of Algorithms taught by Michael A. Bender in Spring 2012. It lists 11 problems related to algorithm analysis and complexity. Students are asked to solve each problem on a separate sheet using LaTeX and submit their problem sets stapled together, indicating which solution they want graded. No late submissions will be accepted.

Uploaded by

stonethumb
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Michael A.

Bender CSE 548 Analysis of Algorithms, Spring 2012 Assignment #1 Due Friday, March 2, 2012

Each of the problems should be solved on a separate sheet of paper to facilitate grading. Please dont wait until the last minute to look at the problems. Im giving you a bit of extra time, since for many of you, this is the rst time that youll be using latex. Make sure that you staple your problem set to your partners problem set. Indicate which one you want graded and put that one rst. If you worked with other people, then please indicate whom you worked with in your solutions and indicate any other sources you relied upon. Please write up solutions using latex. To get latex running on windows, install Miktex and WinEdt on your PC. For the Macintosh, use Texshop, which is part of MacTex. For drawing gures, I recommend using the unix tools xg or inkscape or the Mac tool Omnigrae. Please include at least one gure or example for each problem to get credit. No late problem sets accepted. Problem 1 For the following C codes, nd the time-complexity by rst nding the recurrence relation and then simplifying the recurrence. (1) int blah(int n) { int sum = 0; int i, j; if (n == 0) return 1; for(i=0; i<=n-1; i++) for(j=0; j<=log(n); j++) { . . . loop-body . . . } sum = blah(n/2); sum += blah(n/2); return sum; } (2) int blah(int n) {

int sum = 0; int i, j; if (n == 0) return 7; for(i=0; i<=n-1; i++) sum += blah(i); return sum; } Problem 2 Prove or nd a counterexample for the following. Assume that f (n) and g(n) are grater than 1 and monotonically increasing functions. (1) f (n) = o(g(n)) implies log(f (n)) = o(log(g(n))) (2) f (n) = O(g(n)) implies log(f (n)) = O(log(g(n))) (3) f (n) = o(g(n)) implies 2f (n) = o(2g(n) ) (4) f (n) = O(g(n)) implies 2f (n) = O(2g(n) ) Problem 3 Show that for integer N , aN can be evaluated in O(log N ) multiplications. Describe exactly how many multiplications are required (e.g., no asymptotic notation) in the case where (1) N = 2 , (2) N is an arbitrary integer (E.g., N = n n 1 . . . n1 n0 , ni {0, 1} ). Problem 4 Give asymptotic upper and lower bounds for T (n) in each of the following recurrences. Assume that T (n) is constant for n 2. Make your bounds as tight as possible, and justify your answers. a. T (n) = 3T (n/2) + n. b. T (n) = T ( n) + 1. c. T (n) = T (n 1) + n. d. T (n) = 2T ( n) + 1. Problem 5 Show that the product (a + bi)(c + di) of two complex numbers can be evaluated using just three real-number multiplications. You may use a few extra additions. Problem 6 Suppose that we must sort N numbers, where N is so large that all the numbers do not t in the main memory. Let M be the size of main memory, where N M . The number are stored consecutively on a disk. In one memory transfer a block of B numbers is brought into memory. (Assume that the main memory holds at least 2 blocks. i.e., M 2B + O(1).) Because memory transfers are very expensive, our objective is to minimize the number of memory transfers. Show that we can sort the numbers in O( N logM/B N ) memory transfers. B B

(1) Describe the algorithm. (2) Write down the recursion relation. N Hint: For practice, rst show that standard merge sort uses O( N log M ) memory transfers. B Problem 7 Suppose that we have an array A of n unsorted numbers and an array B of n + 1 unsorted numbers. Now suppose that all the elements of A appear in B and one of the elements of A occurs twice in the array B, how can we tell the value of this element? (1) in O(n log n) time (2) in O(n) time Problem 8 Suppose that you are given a collection of n bolts of dierent sizes, and n corresponding nuts. You can test whether a given nut and bolt together, from which you learn whether the nut is too large, too small, or an exact match for the bolt. The dierences in size between pairs of nuts or bolts can be too small to see by eye, so you cannot rely on comparing the sizes of two nuts or two bolts directly. You are to match each bolt to each nut. (1) Give an O(n2 ) algorithm to solve this problem. (2) Suppose that instead of matching all of the nuts and bolts, you wish to nd the smallest bolt and its corresponding nut. Show that this can be done in only 2n 2 comparisons. Problem 9 Suppose that we have a very large array A stored in row-major order. Your objective is to compute the transpose AT of A. (Transpose of A is also stored in row-major order). Because A is so large, each row of the matrix ts in exactly one page. Because memory transfers are so expensive, once you transfer in a page, computing is essentially free. How many memory transfers do you need to perform the matrix transpose? (Your memory need not be large, it is sucient to have just 2 pages in memory at any time.) Hint: Divide and conquer. Problem 10 A proper linked list consists of a set of nodes two of which, namely the root and the end are distinguished. Each node except the end has one pointer to some other node and each node except the root has pointer from some other node. For each node only the pointer to the next one is given. One can visit the nodes of the list by starting at the root and each time visiting the next node indicated by the pointer. Given a large linked list, we want to determine whether it is a proper list or not; i.e, whether it contains a loop and thus has no end. (1) Give a linear-time algorithm to do this, using a constant number of registers. Your algorithm is not allowed to mark the list. (2) Give a linear-time algorithm that nds, in case the list is improper, the place where the loop starts.

Problem 11 Please give feedback about the problem set. Hard? Easy? Just right? How many hours did you spend working on it? How hard was it to do in latex?

You might also like