CS302 Midterm Exam - October 13, 2015 - Page Two
Question 2
What are the running times of each of the following? Use the answer sheet for this. In the questions that
have both m and n, assume that
m is less than n, and make sure that your answer is as precise as possible. For example,
if something is O(mn), then it is true that it is also O(n^{2}); however, in that
case O(mn) is the correct answer.
- A. Sorting a random vector of n elements with insertion sort.
- B. Creating a map from n elements.
- C. The statement s2 = s1, when s1 is a string with n elements,
and s2 is a string with m elements.
- D. Creating a priority queue from n elements.
- E. Creating a sorted vector from a map with n elements.
- F. Performing n Push() operations on a priority queue with m elements.
- G. The statement s2 = s1.c_str(), when s1 is a string with n elements,
and s2 a (char *) that points to a C-style string with m elements.
- H. Performing m Pop() operations on a priority queue with n elements.
- I. Sorting a random vector of n elements with selection sort.
- J. Finding the m largest elements on a map with n elements.
- K. Sorting a "nearly" sorted vector of n elements with insertion sort.
- L. Finding the m elements that are closest in value to a given element, on a map with n elements.
- M. Performing m Push() operations on a priority queue with n elements.
- N. Erasing m elements from a map with n elements.
- O. Sorting a "nearly" sorted vector of n elements with selection sort.
Question 3
Part A: Which of the following vectors represent binary heaps?
- A-1: { 12, 19, 24, 51, 43, 67, 31, 48, 66, 78 }
- A-2: { 1, 3, 14, 5, 24, 90, 78, 77, 30, 81 }
- A-3: { 18, 20, 20, 37, 41, 64, 34, 44, 38, 85 }
- A-4: { 8, 25, 30, 35, 78, 70, 28, 92, 33, 83 }
Part B: Give me the vector version of the binary heap that results when
you call Push(3) on the following heap: { 9, 23, 11, 57, 38, 17, 12, 86, 88, 80 }
Part C: Give me the vector version of the binary heap that results when
you call Pop() on the following heap: { 6, 17, 45, 21, 26, 51, 52, 74, 67, 89 }