Computer Science II (COP 3503) Fall 2010 Exam #1 9/29/10 Lecturer: Sarah Buchanan Name: ____________________ 1) (5 pts) What is the minimum number of comparisons necessary to sort 14 values, using a comparison sort? Utilize the following information in your solution: 14! ~ 8.72x1010, log28.72 ~ 3.12, and log210 ~ 3.32. You will only get full credit if you utilize the information given and arrive at the correct answer. 2) (10 pts) Determine whether the following statements are true or false. Circle the correct answer. a) n2 /5 = (n2 logn /50) True False b) nlogn = O(200n) True False c) n2 = (n2 logn) True False d) 2n = (2.1n) True False e) log 2 n = (log 200 n) True False 3) (5 pts) What is the most likely theta run-time in terms of n, the input size, of an algorithm that has been measured with the following run-times: n (input size) 1000 2000 4000 8000 16000 T(n) (measured run-time in ms.) 1 7 32 128 512 4) (4 pts) Put a box around the sequence of numbers corresponding to the MCSP of the following sequence of numbers. -8, -2, 7, -5, -2, 5, 0, 11, -3, 10, -8, 5, -4, 7, -1, 5, -4, -5, 3, -6 5) (6 pts) Consider implementing a hash table of size 13 that stores integers with the hash function f(x) = (2x + 5) mod 13 using the quadratic probing strategy. Place the following values in the hash table in the following order: 3, 6, 7, 19, and 32. index 0 1 2 3 4 5 6 7 8 9 10 11 12 value 6) For the following AVL tree operations, show the final AVL tree obtained and all intermediate steps. (a) (5 pts) Determine the AVL tree obtained when the following keys are inserted in the order given: 1,3,2,5,4. 6(b) (5 pts) Delete 12 from the following AVL tree and redraw the tree if it needs rebalancing. Use the inorder predecessor method (replace the deleted node with the largest in its left subtree). 10 / 8 6 / \ 9 \ 7 \ 12 / \ 11 14 / 13 7)(a) (6 pts) Draw the result of inserting 4 into the 2-4 tree shown below. Put a box around your final answer and show all steps. 10, 20, 30 / / \ \ 2, 5, 7 11, 14 27 32, 40 7)(b) (5 points) Show the intermediate steps and final result of deleteMin from the binary heap below. 5 / \ 10 25 / \ / \ 20 15 30 35 8) (5 pts) Draw the Disjoint Set that corresponds to the array representation shown below: index value 1 1 2 1 3 6 4 8 5 8 6 1 7 8 8 8 9) (5 pts) Show the first steps in using Counting Sort to sort a list of integers in the range from 0 to 3 inclusive. Given the unsorted array A, show the array C right before you insert the first value into the output array. Show the first value you would insert into the output array. Array A: index value Array C: index value Output Array: 0 1 index value 1 1 2 2 3 3 4 0 5 1 6 3 7 2 10) For the following code trace problems, write a theta bounds in terms of n for the given pseudocode. Provide proper justification for your answer. (a) (5 points) int i,j; for (i=0,j=0; i<n; i++) { while (i < n) { count++; i++; while (j < n) { count++; j++; } } } (b) (5 points) while (n > 0) { for (int i=1; i<=n; i++) count++; n = n / 3; } (c) (5 points) for (i = 1; i <= n*n; i++) for (j = 1; j <= 5 * n; j++) count++; for (i = 1; i <= 3 * n; i++) count++; 11) (20 points) Suppose you have 2 text files listing a series of unsorted integers, and you want to output only the integers the two files have in common into a new file. a) Describe an efficient algorithm to solve this problem using a Binary Heap. Give the run time of this algorithm along with proper justification. b) Describe an efficient algorithm to solve this problem using a Hash Table. Give the run time of this algorithm along with proper justification. (Hint: You can assume for this problem that you have a perfect hash function that maps each distinct integer to a distinct hash table location.) 12)(4pts) What’s your favorite sorting algorithm and why? (There’s no wrong answer for this question, except a blank answer!) Scratch Page – Please clearly mark any work on this page you would like graded.