What are the complexity guarantees of the standard containers?

I found the nice resource Standard C++ Containers. Probably this is what you all looking for. VECTOR Constructors vector<T> v; Make an empty vector. O(1) vector<T> v(n); Make a vector with N elements. O(n) vector<T> v(n, value); Make a vector with N elements, initialized to value. O(n) vector<T> v(begin, end); Make a vector and copy … Read more

Big-O summary for Java Collections Framework implementations? [closed]

The book Java Generics and Collections has this information (pages: 188, 211, 222, 240). List implementations: get add contains next remove(0) iterator.remove ArrayList O(1) O(1) O(n) O(1) O(n) O(n) LinkedList O(n) O(1) O(n) O(1) O(1) O(1) CopyOnWrite-ArrayList O(1) O(n) O(n) O(1) O(n) O(n) Set implementations: add contains next notes HashSet O(1) O(1) O(h/n) h is … Read more

Are there any worse sorting algorithms than Bogosort (a.k.a Monkey Sort)? [closed]

From David Morgan-Mar’s Esoteric Algorithms page: Intelligent Design Sort Introduction Intelligent design sort is a sorting algorithm based on the theory of intelligent design. Algorithm Description The probability of the original input list being in the exact order it’s in is 1/(n!). There is such a small likelihood of this that it’s clearly absurd to … Read more

How to find the kth largest element in an unsorted array of length n in O(n)?

This is called finding the k-th order statistic. There’s a very simple randomized algorithm (called quickselect) taking O(n) average time, O(n^2) worst case time, and a pretty complicated non-randomized algorithm (called introselect) taking O(n) worst case time. There’s some info on Wikipedia, but it’s not very good. Everything you need is in these powerpoint slides. … Read more

Are there any cases where you would prefer a higher big-O time complexity algorithm over the lower one?

There can be many reasons to prefer an algorithm with higher big O time complexity over the lower one: most of the time, lower big-O complexity is harder to achieve and requires skilled implementation, a lot of knowledge and a lot of testing. big-O hides the details about a constant: algorithm that performs in 10^5 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)