*Setup*

. We will aggregate (discounted) prices of all qualifying products and compare the total (discounted) prices against threshold tier(s).*Qualifying products*. If qualified, we will apply the discount to the applying products. In many cases, they are the same as qualifying products, but they can be different.*Applying products*. In general, we use amount to define the threshold, and discount method can be either amount off or percentage off. It is also possible to have multiple threshold tiers.*Qualifying threshold and discount method*

One of key difference between threshold discounts and non-threshold discounts is that** you can apply threshold discount only once per checkout cart**. For example, say you see a threshold discount of $10 off if you buy $100+. If you have $200+ in the cart that can be split into two groups, each of $100+, we still give you $10 total. In other words, we do not split the products to apply them more than once.

*How to apply the threshold discount when it is the only discount for the checkout cart?*

It is straightforward to figure out the discount and allocation, following the threshold discount definition.

** Threshold discount competes with non-thresholds**.

Threshold discount is not fit for knapsack problem in that it would drag down the performance of any knapsack problem because it can generate tons of ** basic discount applications**. Take a checkout cart of 10 different products, each of quantity 1, and ignore the threshold qualification for a second, how many basic discount applications can you have?

Secondly, the result may not be intuitive. For example, two exclusive discounts: a simple discount of $1 off for one keyboard, and a threshold discount of $10 off if you spend more than $100. If you buy 10 keyboards with $20 each. To get the best deal out of the knapsack problem, we would split 20 keyboards into two groups: one group of quantity 15 for simple discount and another group of quantity 5 for threshold discounts.

The recommendation is to leave threshold discounts out of non-threshold discount knapsack problem, and evaluate them after we have evaluated non-threshold discounts.

** Threshold discount competes with other threshold discounts**.

Strictly speaking, the competition between threshold discounts is a knapsack problem, but it is different from the one between non-threshold discounts.

- Competition is rare, and is often between two threshold discounts.
- When there is a competition, functionally more often than not, they cover same set of products, so it is really picking one over the other.
- On the functional side, it is not about splitting products to accommodate all threshold discounts to maximize the deal, unlike the case with non-threshold discounts.

I do not think the traditional knapsack algorithm is a good fit. Instead, functionally, it make more sense to rank them in some way, and apply in that order. Technically, it is superior too.

*Compounding*

Let me just say it is big relief for threshold discount compounding, comparing to non-threshold compounding.

*Rounding*

Rounding is not easy. Forgive me for just leaving it like that for now.