How to apply binary search O(log n) on a sorted linked list?

It is certainly not possible with a plain singly-linked list. Sketch proof: to examine the last node of a singly-linked list, we must perform n-1 operations of following a “next” pointer [proof by induction on the fact that there is only one reference to the k+1th node, and it is in the kth node, and … Read more

How can I interleave or create unique permutations of two strings (without recursion)

Your problem can be reduced to that of creating all unique permutations of a particular list. Say A and B are the lengths of the strings arr1 and arr2, respectively. Then construct a list like this: [0] * A + [1] * B There exists a one-to-one correspondence (a bijection) from the unique permutations of … Read more

Haskell GHC: what is the time complexity of a pattern match with N constructors?

A jump table is used, making the pattern-match a constant time operation. Unfortunately I’m unable to find an up-to-date citation for this, although this page mentions the implementation of Cmm-level switch statements as jump tables, and this old tagging design document uses a case on a Bool as an example, producing a jump table.

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

Is there anything that guarantees constant time for accessing a property of an object in JavaScript?

Is there anything in the JavaScript guaranteeing that the values are looked up in O(1) time? No. JavaScript does not give any complexity guarantees whatsoever, except for ES6 collections. I know the access operator [] gives a seasoned programmer the impression that he’s dealing with an O(1) lookup structure Yes you are, this is a … Read more