Fall 2013 CSE310 Midterm 2D in class Instructions There are six problems in this paper Please use the space provided below the questions to write the answers Budget your time to solve various problems roughly 15 minutes for each problem and avoid spending too much time on a particular question This is a closed book examination You may not consult your books notes Cell phones and computers are not allowed However you can use a basic calculator You are NOT supposed to use a pencil If you use a pencil you cannot challenge your grade after the midterm is graded NAME ASUID Question Score P1 P2 P3 P4 P5 P6 Total 0 Problem 1D 10 points 2 2 2 2 2 Array A contains 10 elements from index 1 to index 10 as shown in the following i 1 A i 19 2 3 4 5 6 7 17 15 13 11 9 7 8 9 10 5 3 1 Suppose you are applying the linear time buildheap algorithm to build a min heap from the 10 elements of array A For i 5 4 3 2 1 show the array structure after the call to min heapify A i is completed using the table provided below After min heapify A 5 the array structure is i 1 A i 19 2 3 4 5 6 7 17 15 13 1 9 7 8 9 10 5 3 11 After min heapify A 4 the array structure is i 1 A i 19 2 3 4 5 6 7 17 15 3 1 9 7 8 9 10 5 13 11 After min heapify A 3 the array structure is i 1 A i 19 2 3 4 5 6 7 17 7 3 1 9 15 8 9 10 5 13 11 After min heapify A 2 the array structure is i 1 A i 19 2 3 4 5 6 7 1 7 3 11 9 15 8 9 10 5 13 17 After min heapify A 1 the array structure is i 1 A i 1 2 3 4 5 6 7 3 7 5 11 9 15 1 8 9 10 19 13 17 Problem 2D 10 points 2 2 2 2 2 Array B contains 10 elements from index 1 to index 10 as shown in the following i 1 2 B i 1 3 3 4 5 6 7 5 7 9 11 13 8 9 10 15 17 19 Suppose you are inserting these 10 elements in the given order into an originally empty min heap implemented in array A For i 6 7 8 9 10 show the array structure after the first i elements are inserted into the min heap using the table provided below After inserting the first 6 elements the array structure is i 1 2 3 4 A i 1 3 5 7 5 6 7 8 9 10 9 11 After inserting the first 7 elements the array structure is i 1 A i 1 2 3 4 5 6 7 3 5 7 9 11 13 8 9 10 After inserting the first 8 elements the array structure is i 1 2 3 4 A i 1 3 5 7 5 6 7 8 9 10 9 11 13 15 After inserting the first 9 elements the array structure is i 1 A i 1 2 3 4 5 6 7 3 5 7 9 11 13 8 9 10 15 17 After inserting the first 10 elements the array structure is i 1 A i 1 2 3 4 5 6 7 3 5 7 9 11 13 2 8 9 10 15 17 19 Problem 3D 20 points 5 5 5 5 In class we have studied the linear time selection algorithm with group size 5 Suppose we will use group size 23 instead of 5 Again we are using the median of medians as the pivot element Assume that there are n elements and all elements are distinct 5pts What is the maximum number of elements that can appear on either side of the pivot element You should not use the asymptotic notations Answer 17n 23 24 5pts Let T23 n denote the worst case time complexity of your algorithm Write down the recurrence formula for T23 n n T23 17n 24 bn Answer T23 n T23 23 23 5pts Use the asymptotic notations to denote T23 n as a function of n Answer T23 n O n 5pts Suppose you modify the original quicksort algorithm by using the median computed by the linear time selection algorithm as the pivot element Let T n denote the worst case time complexity of this modified quicksort algorithm for sorting n elements Use the asymptotic notations to denote T n as a function of n Answer T n O n log n 3 Problem 4D 20 points 4 4 4 4 4 A disjoint set structure is given by the following array structure We are using union by rank and find with path compression i 1 A i 3 2 3 4 5 6 7 1 1 3 1 5 5 8 9 10 7 3 9 11 12 13 14 15 16 9 11 9 13 13 13 4pts Given the array structure at the top of this page apply the operation union 7 16 Write down the resulting array structure in the following table i 1 2 3 4 5 6 A i 9 1 1 3 1 5 7 8 9 1 7 4 10 11 12 13 14 15 9 9 11 9 13 13 16 9 4pts Given the array structure at the top of this page apply the operation find set 8 Write down the resulting array structure in the following table i 1 2 3 4 A i 3 1 1 3 5 6 7 8 9 10 11 12 13 1 5 1 1 3 9 9 11 9 14 15 16 13 13 13 4pts Given the array structure at the top of this page apply the operation link 1 9 Write down the resulting array structure in the following table i 1 2 3 4 5 6 A i 9 1 1 3 1 5 7 8 9 5 7 4 10 11 12 13 14 15 9 9 11 9 13 13 16 13 4pts Given the array structure at the top of this page apply the operation union 5 10 Write down the resulting array structure in the following table i 1 2 3 4 5 6 A i 9 1 1 3 1 5 7 8 9 5 7 4 10 11 12 13 14 15 9 9 11 9 13 13 16 13 4pts Suppose we are using union by rank and find with path compression Applying a total of m operations to a disjoint set with n elements what is the total number of basic operations required You should use asymptotic notation to give the most accurate bound Answer O m m n 4 Problem 5D 20 points 5 5 5 5 The following four questions deal with binary search trees …
View Full Document
Unlocking...