12.07.2015 Views

CMSC 441 SPRING 2010 HOMEWORK 2 DUE: MARCH 25, 2010, 4 ...

CMSC 441 SPRING 2010 HOMEWORK 2 DUE: MARCH 25, 2010, 4 ...

CMSC 441 SPRING 2010 HOMEWORK 2 DUE: MARCH 25, 2010, 4 ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>CMSC</strong> <strong>441</strong> <strong>SPRING</strong> <strong>2010</strong> <strong>HOMEWORK</strong> 2<strong>DUE</strong>: <strong>MARCH</strong> <strong>25</strong>, <strong>2010</strong>, 4:00 PM, IN CLASSIn this course, all course work, including, but not limited to, thishomework, shall be your own individual work. Working with anotherperson or with other persons on any course work related tothis course, including, but not limited to, this homework, is prohibitedand is a violation of UMBC’s academic conduct policy. Itis your responsibility to find and read UMBC’s academic conductpolicyIn each answer show all your work and describe in detail how youobtained the solution.1) [10%] Let A be an array with heap-size[A]=11 such that A[1]=22, A[2]=8,A[3]=12, A[4]=15, A[5]=6, A[6]=5, A[7]=10, A[8]=8, A[9]=12, A[10]=4,A[11]=3. Provide the values of A[t] fort=1,2,3,4,5,6,7,8,9,10,11 after each execution of exchange A[i] ↔ A[largest]during the execution of MAX-HEAPIFY(A,2).2) [10%] Consider the operation of BUILD-MAX-HEAP(A) on the arrayA such that length[A]=9 and A[1]=6, A[2]=20, A[3]=4, A[4]=12, A[5]=11,A[6]=3, A[7]=18, A[8]=11, A[9]=21. Provide the values of A[i] for i=1,...,9after the completion of each execution of MAX-HEAPIFY inside BUILD-MAX-HEAP.3) [10%] Consider the operation of BUILD-MAX-HEAP(A) on the arrayA such that length[A]=9 and A[1]=3, A[2]=2, A[3]=20, A[4]=5, A[5]=15,A[6]=4, A[7]=22, A[8]=8, A[9]=21. Provide the values of A[i] for i=1,...,9after the completion of each execution of MAX-HEAPIFY inside BUILD-MAX-HEAP.4) [15%] Let T(n) be the running time of MAX-HEAPIFY(A,1) on an array Awith heap-size[A]=length[A]=n that satisfies A[i] ≥ A[i+1] for i = 1, ..., n−1.Provide a formula for a function g(n) such that T(n) = Θ(g(n)). Prove thatyour formula is correct.


5) [15%] Exercise 12.2-1 in the text. Assume that the tree search is performedby executing TREE-SEARCH(x,k), where k=363. TREE-SEARCH(x,k) isas given in the text. For each one of the given sequences that could notbe the sequence of nodes examined, prove that it could not be the sequenceof nodes examined. For each one of the given sequences that could be thesequence of nodes examined, prove that it could be the sequence of nodesexamined.6) [15%] Exercise 12.2-5 in the text. In that exercise, interpret “show that”as “prove that”. For a node u in a binary search tree such that u has two children,the successor of u is the node returned by TREE-MINIMUM(right[u]),and the predecessor of u is the node returned by TREE-MAXIMUM(left[u]).TREE-MINIMUM and TREE-MAXIMUM are procedures in the text.7) [10%] Exercise 16.3-2 in the text, only for the given eight characters a, b,c, d, e, f, g, h with the given eight frequencies, and not for general n. Use theprocedure HUFFMAN in the text. An optimal Huffman code is a minimumcost binary prefix code.8) [15%] Let C be a set of 2 n characters. Suppose that n is a positive integer,and that there exists a positive constant d such that for every member x ofC, its frequency f[x] is equal to d. Prove that the cost of a minimum costbinary code for C with that f is dn2 n .

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!