e-commerce: Algorithm for calculating discounts

Assuming that: You can compute all available discounts based on your basket Each product can only have a single discount applied to it Each discount can only be used once Then the problem becomes one that is called an assignment problem and can be optimally solved in O(n^3) using the Hungarian algorithm. You will need … Read more

What is the lookup time complexity of HashSet(IEqualityComparer)?

A HashSet works via hashing (via IEqualityComparer.GetHashCode) the objects you insert and tosses the objects into buckets per the hash. The buckets themselves are stored in an array, hence the O(1) part. For example (this is not necessarily exactly how the C# implementation works, it just gives a flavor) it takes the first character of … Read more

Can any finite bit string be found in pi within a reasonable amount of time? [closed]

Expanding on my comments. There’s a very important concept here that’s called information entropy. Out of full disclosure, I’m the current world record holder of the digits of Pi at 10 trillion digits (10^13). I have approximately 10,000 copies of everyone’s social security number. However that doesn’t mean I can just hack into everyone’s accounts … Read more

C++ set: counting elements less than a value

What you need is an ‘order-statistics tree’. It is essentially an augmented (binary search) tree that supports the additional operation rank(x) which gives you the number of elements with less or equal key as element x. Chapter 14 in Cormen, Leiserson, Rivest, Stein; “Introduction to Algorithms” should give you the algorithmic background. There is also … Read more

Constructing efficient monad instances on `Set` (and other containers with constraints) using the continuation monad

Monads are one particular way of structuring and sequencing computations. The bind of a monad cannot magically restructure your computation so as to happen in a more efficient way. There are two problems with the way you structure your computation. When evaluating stepN 20 0, the result of step 0 will be computed 20 times. … Read more

String analysis

This whole problem is known as “Common Subexpression Elimination” or CSE. It is a slightly smaller version of the problem called “Graph Reduction” faced by the implementer of compilers for functional programming languages. Googling “Common Subexpression elimination algorithm” gives lots of solutions, though none that I can see especially for the constraints given by matrix … Read more

techhipbettruvabetnorabahisbahis forumu