0% found this document useful (0 votes)
110 views1 page

The Running Times: O (log (n) ) O (n) O (α (n) ) O (log (n) ) O (log (n) ) O (log (n) ) O (log (n) )

The document contains running times for various algorithms: 1. Common operations on maps, heaps, and disjoint sets have logarithmic or constant time complexity, such as deleting from a map (O(log(n))), pop from a heap (O(log(n))), and union on a disjoint set (O(1)). 2. Sorting algorithms like insertion sort and bubble sort have quadratic time complexity (O(n^2)), while heap sort, multiset sort, and STL sort are faster at O(n log n). 3. Operations on heaps like creating a heap from a vector and push/pop can be done in linear or logarithmic time respectively.

Uploaded by

dinban1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views1 page

The Running Times: O (log (n) ) O (n) O (α (n) ) O (log (n) ) O (log (n) ) O (log (n) ) O (log (n) )

The document contains running times for various algorithms: 1. Common operations on maps, heaps, and disjoint sets have logarithmic or constant time complexity, such as deleting from a map (O(log(n))), pop from a heap (O(log(n))), and union on a disjoint set (O(1)). 2. Sorting algorithms like insertion sort and bubble sort have quadratic time complexity (O(n^2)), while heap sort, multiset sort, and STL sort are faster at O(n log n). 3. Operations on heaps like creating a heap from a vector and push/pop can be done in linear or logarithmic time respectively.

Uploaded by

dinban1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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).

You might also like