Sei sulla pagina 1di 1

THE RUNNING TIMES

2013 Mid-Term

A. Deleting an element from a map with n elements: O(log(n))
B. Constructing a heap from a vector with n elements: O(n)
C. Performing union() on a disjoint set instance with n elements: O(1)
D. Performing find() on a disjoint set instance with n elements: O((n))
E. Performing upper_bound() on a map with n elements: O(log(n))
F. Inserting an element into a map with n elements: O(log(n))
G. Performing pop() on a heap with n elements: O(log(n))
H. Performing push() on a heap with n elements: O(log(n))

2012 Mid-Term
A. Sorting a vector using insertion sort. O(n2)
B. Sorting a vector using heap sort. O(n log n)
C. Calling Push() on a heap. O(log n)
D. Creating a heap from a random vector. O(n)
E. Calling Pop() on a heap. O(log n)
F. Printing all elements of a map in order. O(n)
G. Printing all subsets of a set. O(2n)
H. Calling Union() on a disjoint set. O(1)
I. Deleting an element from a map. O(log n)
J. Printing all pairs of elements in a vector of integers. O(n2)
K. Inserting an element into a map. O(log n)
L. Sorting a vector using selection sort. O(n2)
M. Sorting a vector using bubble sort. O(n2)
N. Calling Find() on a disjoint set. O((n))
O. Sorting a vector using STL multisets. O(n log n)
P. Enumerating all 2-disk failures in an n-disk system. O(n2)

2009 Mid-Term
A. Inserting an element into a map. Same as a balanced binary tree: O(log2(n)).
B. Creating a heap from a vector. This is where a heap excels over a set or map, because you can create a heap
from a vector in linear time: O(n).
C. Finding the minimum element of a priority queue. The minimum element is at the root of the heap: O(1).
D. Inserting an element into a priority queue. Add the new element to the back of the vector and percolate up:
O(log2(n)).
E. Appending an element to a vector. This is a constant time operation: O(1).
F. Counting the number of unique elements of a multiset. You need to traverse the multiset with an iterator: O(n).
G. Creating a sorted vector from a multiset that has n elements. Again, this simply requires traversing the multiset
with an iterator: O(n).
H. Sorting a nearly sorted vector using selection sort. There is no advantage to having the vector nearly sorted --
selection sort still takes O(n2) operations.
I. Deleting an element from a list: O(1).
J. Sorting a nearly sorted vector using insertion sort. This is where insertion sort does well: O(n).

Potrebbero piacerti anche