Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8214389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:26:46+00:00 2026-06-07T11:26:46+00:00

Here’s the problem: A user has a shopping basket containing items, where each item

  • 0

Here’s the problem:

A user has a shopping basket containing items, where each item has a set of available delivery types which is a subset selected from some defined overall set (e.g. [“UK 2nd class”, “UK 1st class”, “UK Recorded Delivery”], but don’t get too hung up on the exact names).

When going through the checkout process, the user should be presented with the option of either separate or combined delivery.

Separate is easy – a table is displayed where each item is on its own row, and the set of columns matches the union of available delivery types among the items. Each row contains a radio button set, one button for each column that is of a delivery type available to that item.

It’s combined I’m unsure how to approach. Items can be combined into a group only when all items in that group share a subset of available delivery types. Items with mutually exclusive delivery types can never be in the same group. The basket can contain items from multiple vendors; when this is the case, products from different vendors may not be grouped together, even if they share a delivery type.

The client requires that the minimum number of groups is calculated, irrelevant of the cost of each type of postage. Yes, that means that if separate deliveries for four items would cost £1+£2+£3+£4 (four different delivery types), but the items all share a fifth delivery type that costs £15, then the user would be presented with that single more-expensive group for the “combined” option.

Here is an HTML example of separate/combined options.

The available delivery types for an item are retrieved from the database using a stored procedure, and have a unique identifier created from the type ID and vendor ID, so that it’s easy to compare equality between types. However, I can’t seem to conjure up an efficient algorithm for doing the comparisons and generating groups.

The end result I’m hoping for in terms of data structures is (pseudo-code):

Basket { List<Item> Items }
=>
GroupsTable {
    List<SelectableDeliveryType> Columns,
    List<Group { List<Item> }> Rows
}

Where each Item contains its own List<AvailableDeliveryType> which can easily then be used to work out which SelectableDeliveryType column to put its radio buttons in.

Any thoughts, pointers to general algorithmic concepts which cover this (I don’t think it’s a set cover problem for example) etc. greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T11:26:48+00:00Added an answer on June 7, 2026 at 11:26 am

    This problem is NP-hard by a reduction from graph coloring. Given a graph consisting of a set of nodes connected by edges, a k-coloring in that graph is a way of coloring each node in the graph so that no two connected nodes have the same color. The chromatic number problem is the following – what is the minimum number of colors with which it is possible to color a graph?

    We can reduce any instance of the chromatic number problem, which is NP-hard, to your problem as follows: for each node, create a new product. For each edge, mark that those two products cannot be grouped into the same cluster. Then, any clustering of these products corresponds to a coloring – just color all the nodes in each cluster the same color. Consequently, solving your problem optimally is equivalent to solving graph coloring, and therefore (under the assumption that P ≠ NP) has no polynomial-time algorithm.

    Unfortunately, graph coloring is known to be very hard to approximate; there is no known polynomial-time algorithm that can get within a constant factor of optimal, or even within a factor of n1-ε for any ε > 0. I think you are best off going with a heuristic like Chaitin’s algorithm, or finding a different way of thinking about this problem.

    Sorry for the negative result, but hopefully this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Basically, what I'm trying to create is a page of div tags, each has
Here is my problem : I have a post controller with the action create.
Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the
Here is the problem that I am trying to solve. I have two folders
Here is my program to find all the subsets of given set. To solve
Here is what is supposed to happen: The moment the user chooses an option
Here's the flow that I am trying to achieve: 1) User uploads an audio
Here is another spoj problem that asks how to find the number of distinct
Here's a problem I ran into recently. I have attributes strings of the form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.