multiset, map and hash map complexity

map, set, multimap, and multiset These are implemented using a red-black tree, a type of balanced binary search tree. They have the following asymptotic run times: Insertion: O(log n) Lookup: O(log n) Deletion: O(log n) hash_map, hash_set, hash_multimap, and hash_multiset These are implemented using hash tables. They have the following runtimes: Insertion: O(1) expected, O(n) … Read more

Examples of Algorithms which has O(1), O(n log n) and O(log n) complexities

If you want examples of Algorithms/Group of Statements with Time complexity as given in the question, here is a small list – O(1) time Accessing Array Index (int a = ARR[5];) Inserting a node in Linked List Pushing and Poping on Stack Insertion and Removal from Queue Finding out the parent or left/right child of … Read more

What are the rules for the “Ω(n log n) barrier” for sorting algorithms?

To directly answer your question: Your sorting algorithm is technically not O(n) but rather O(n + max), since you need to create an array of size max, which takes O(max) time. This isn’t a problem; in fact, it’s a special case of a well-known sorting algorithm that breaks the Ω(n log n) barrier. So what … Read more

What’s the time complexity of array.splice() in Google Chrome?

Worst case should be O(n) (copying all n-1 elements to new array). A linked list would be O(1) for a single deletion. For those interested I’ve made this lazily-crafted benchmark. (Please don’t run on Windows XP/Vista). As you can see from this though, it looks fairly constant (i.e. O(1)), so who knows what they’re doing … Read more

Complexity of list.index(x) in Python

It’s O(n), also check out: http://wiki.python.org/moin/TimeComplexity This page documents the time-complexity (aka “Big O” or “Big Oh”) of various operations in current CPython. Other Python implementations (or older or still-under development versions of CPython) may have slightly different performance characteristics. However, it is generally safe to assume that they are not slower by more than … Read more