0

There are a total of n questions available. The objective is to find and generate as many quizzes as possible with the following conditions.

INPUT :

  • Each question belongs to any one of the 3 categories. namely JAVA ,PYTHON and MYSQL
  • Each question belongs to any one of the 2 difficulty level. EASY and DIFFICULT

RULES THAT A QUIZ MUST SATISFY :

  • There must be at least 1 question from each category(java | python | mysql).

  • at least 2 questions from each difficulty level.

  • A quiz must contain exactly 5 questions. (Lets call this number K)

  • A question once added to a quiz, can not repeat in any other quiz.

I've tried the naive way with following strategy:

  • Form n/k groups.

  • If there are 15 questions and k=4 , we can form at most 15/4=3 quizzes (groups).

  • For each group, iterate through questions and add them to that group if it satisfies the conditions.

  • If a question is added, decrement the quiz's difficulty requirement and category requirement

Once we have groups with minimum conditions satisfied, iterate through the leftover questions and add them to quizzes so that the quiz will contain K questions.

The problem with this is, It only works if the input questions are in a specific favorable order. I ran the program with input questions randomly shuffled. I got different outputs. (I can share the code if required)

So, what I understood is, the above solution is not reliable. We have to exhaustively check for all combinations of questions. This seemed to be very similar to Minimum coins change problem.

This is different from MCC in following ways

  1. There are only limited supply of coins. {1,1,2,2,2,3,4,5}
  2. We don't need number of coins but group of coins that satisfy some conditions.
  3. Maximize. not minimize.
  4. Maximize the number of groups(not coins) that satisfy given conditions.

I know there exists a DP solution for this. I spent a couple of days trying to get the reccurence relation. But I could not arrive at one.

How can I solve this using DP? How can I derive the recurrence relation for this problem? Please start with recursive solution if possible

Arun Gowda
  • 2,721
  • 5
  • 29
  • 50

1 Answers1

0

An idea based on cliques:

consider the N valid quizzes (N < C_n^5). We want to make a family of quizzes (the biggest possible) such that its quizzes are disjoint: they have no question in common.

  • Say a quizz is a node (of a graph G)
  • A quizz is in relation with an other quizz if NO question in common: there exists an edge.
  • Build the maximum clique of G.

If you have to write it by hand, consider the following algo for the maximum clique:

function buildClique(clique, nodes)
  if nodes.empty
    return clique

  n = nodes[0]
  if clique + n is not a clique
    return buildClique(clique, nodes - n)

  return max( //consider returning the clique which is the biggest
    buildClique(clique + n, nodes - n) // add the node to the clique
    buildClique(clique, nodes - n) // do not add it
  )

You'd take the biggest clique by building the biggest clique from each node

bestClique = []
forall nodes as n
  clique = buildClique([n], nodes - n)
  if size(clique) > size(bestClique)
    bestClique = clique

DP wise (by stating that the maximum clique is composed of cliques of lesser size), we may

  • build all cliques of size 1,
  • build those of size 2 by adding "compatible" node to each clique of size 1
  • and so forth
  • until there is no cliques of size m: we can take any clique of size m-1
grodzi
  • 5,633
  • 1
  • 15
  • 15