longQuestions

longQuestions - Summer 2011 Long Answer 1. Two int arrays,...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Summer 2011 Long Answer 1. Two int arrays, A and B , contain m and n int s each, respectively. The elements within each of these arrays appear in ascending order without duplication (i.e. each table represents a set). Give Java code for a algorithm to find the set difference by producing a third array C (in ascending order) with the values that appear in A, but not B , and sets the variable p to the final number of elements copied to C . (Details of input/output, allocation, declarations, error checking, comments and style are unnecessary .) 15 points Example: A = {1, 2, 4, 5, 7, 11}, B = {0, 1, 2, 6, 7, 13}, C = {4, 5, 11}, p = 3 2. Use the recursion-tree method to show that is in . 10 points 3. Use the substitution method to show that is in . 10 points 4. Complete the function by writing the code to replace each ??? on the line to its right. 10 points public static <T extends Comparable<? super T>> int binSearchFirst(T[] a,T key) throws ClassCastException { // Finds index of first slot with a key >= a given key // WARNING - Returns n if key>a[n-1] int low,high,mid,order; int n=a.length; low=0; high=???; __________________ while (low???high) __________________ { mid=???; __________________ order=a[mid].compareTo(key); if (order???0) __________________ low=mid+1; else high=mid-1; } return ???; __________________ } 5. Use the efficient construction to convert into a minHeap. 5 points 11 6 1 10 8 4 3 2 5 1 2 3 4 5 6 7 8 9 9 10 7 11 1 2 3 4 5 6 7 8 9 10 11 6. Show the maxheap after changing the priority at subscript 6 to 9. 5 points
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 3 1 4 5 6 7 1 2 3 4 5 6 7 8 2 1 2 3 4 5 6 7 8 Fall 2011 Long Answer 1. Two int arrays, A and B , contain m and n int s each, respectively with m<=n . The elements within both of these arrays appear in ascending order without duplicates (i.e. each table represents a set). Give C code for a algorithm to test set containment ( A B ) by checking that every value in A appears as a value in B . If set containment holds, your code should return 1 . If an element of A does not appear in B , your code should return 0 . (Details of input/output, allocation, declarations, error checking, comments and style are unnecessary .) 15 points 2. Use the recursion-tree method to show that is in . 15 points 3. Use the substitution method to show that is in . 15 points Spring 2010 Long Answer 1. Prove that if then . 5 points 2. Use dynamic programming to solve the following instance of weighted interval scheduling. Be sure to indicate the intervals in your solution and the sum achieved. 10 points 1 6 11 16 21 26 1 2 3 4 5 6 7 8 9 10 v i p i 1 0 5 0 3 2 8 1 1 4 2 4 3 5 1 6 4 6 1 8 m ( i ) 3. Give the greedy solution for the unweighted interval scheduling problem using the set of intervals for problem 2. You may simply give the indices for the intervals in the solution. 10 points 4. a. Show the maxheap after performing getmax . 5 points
Background image of page 2
9 2 3 4 1 6 5 8 7 1 2 3 4 5 6 7 8 9 b. Show the minheap after changing the priority at subscript 4 to 1. 5 points
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

longQuestions - Summer 2011 Long Answer 1. Two int arrays,...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online