CS302 Fall 2009 Midterm Exam

James S. Plank. October 13, 2009

Question 1

For each of the given activities, state its running time complexity from the list of answers below. Unless otherwise stated, assume that the data structure (map, vector, set, priority queue, etc) has n elements. Use the answer sheet.

List of Activities

Activity 1:Inserting an element into a map.
Activity 2:Creating a heap from a vector.
Activity 3:Finding the minimum element of a priority queue.
Activity 4:Inserting an element into a priority queue.
Activity 5:Appending an element to a vector.
Activity 6:Counting the number of unique elements of a multiset.
Activity 7:Creating a sorted vector from a multiset that has n elements.
Activity 8:Sorting a nearly sorted vector using selection sort.
Activity 9:Deleting an element from a list.
Activity 10:Sorting a nearly sorted vector using insertion sort.

List of Answers

b.O(1 - e-λn)
i.O(n log2(n))

Question 2

Below are six vectors. For each, state whether it represents a valid heap or not. For the purposes of this question, a heap may have duplicate values. Use the answer sheet.

Vector 1:
Vector 2:
Vector 3:
Vector 4:
Vector 5:
Vector 6: