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 6031519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:11:44+00:00 2026-05-23T05:11:44+00:00

In my workplace I have stumbled upon the following problem that I am asked

  • 0

In my workplace I have stumbled upon the following problem that I am asked to solve. A solution is preferred although not absolutely required.

There is a database with a set of stories, and each story has a set of topics associated with it. The topics are stored in a separate table of the form (storyid, topicid).

The question is how to select ideally 5 topics (or at least 2, if 5 is impossible) such that each topic has 2 stories (or 1, if 2 is impossible) that are not repeated in any of the other selected topics. The algorithm must also return which exactly are the “proper” stories associated with each topic.

Is this actually an NP-complete problem that has no efficient solution that goes beyond simple enumeration of all possibilities or does it have an efficient solution?

If it does not have an efficient solution, please try to prove it (although not absolutely necessary).

If it does have an efficient solution, please be kind and post it.

  • 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-05-23T05:11:45+00:00Added an answer on May 23, 2026 at 5:11 am

    A more general version of the problem is to select for all topics (or at least as many as possible) two stories so that the same story is never selected for two different topics.

    Mark the stories with S1…Sm, and the topics with T1…Tn. Duplicate each topic, that is, introduce the new stories T’1…T’n, where T’i contains Sj if and only if Ti contains it. The problem can now be rephrased this way: select a different story for all topics (or as many as possible). Once you have your topic-story pairs, you can join the duplicated topics again, and each topic will have two stories.

    The problem of finding the largest number of pairs possible while never selecting any element twice is called the maximum bipartite matching problem. (You can think of it as selecting the maximum number of non-connected edges from a bipartite graph.) There is a simple algorithm called augmenting path which solves it in O((m+n)e) steps (e being the number of edges) and some more sophisticated ones (such as the Hopcroft–Karp algorithm) which solve it in around O((m+n)^2.5) steps. The augmenting path algorithm consists of searching for “alternating” paths in the graph where the first edge of the path is not selected, the second is, the third isn’t and so on, than inverting the selections on the path. This can be probably adapted to your case without actually doing the splitting and joining of topics.

    This is a bit of an overkill because it will return two stories for all the topics, not only five; you can probably do a lot better when you only need to find stories for a limited number of topics. (Except for some edge cases, you can just select the five topics which have the largest number of stories, discard the stories not contained by them, and run the algorithm then.) At any rate it shows that the problem is far from being NP-hard.

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

Sidebar

Related Questions

At my workplace, we just stumbled upon the problem where we need to create
I have the following problem that I need to express. There are persons, workplaces
I have a User model, which has a workplace attribute. The Workplace is not
At my workplace we deploy internal application by only replacing assemblies that have changed
I seem to have stumbled over a problem regarding saving an xml file from
My work place is developing code for some absolutely ancient hardware that doesn't have
At my workplace, we have lab machines that we use to do our testing.
We use a websense internet filter at my workplace. I have an application that
I have an custom addon developed for our workplace (using the add-on SDK) that
I've just been informed at my workplace that we have an application that is

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.