pattern matching - Algorithm for impelemnting a survey-like program -


i wish create program in java ask user number of questions , report results. pretty survey. in order explain problem better consider following example: let’s there 4 questions available eg qa, qb, qc , qd. each question has number of possible options:

=> question has 4 possible options a1, a2, a3 , a4.

=> question b has 3 possible options b1, b2 , b3

=> question c has 5 possible options c1, c2, c3, c4 , c5

=> question d has 2 possible options d1 , d2

moreover there results available reported based on user’s answers in above questions. let’s assume there 5 such results called r1, r2, r3, r4 , r5. each result has number of characteristics. these characteristics answers above questions. more precisely:

=> characteristics of r1 set of {qa = a4, qb = b2, qc = c2, qd = d1} says r1 related qa via a1 option, qb via b2 option , on

=> r2: {qa = a3, qb = b3, qc = c3, qd = d2}

=> r3: {qa = a4, qb = b1, qc = c1, qd = d2}

=> r4: {qa = a2, qb = b2, qc = c5, qd = d1}

=> r5: {qa = a1, qb = b3, qc = c4, qd = d2}

let’s user u provides following answers questions {qa = a4, qb = b1, qc = c1, qd = d1}

the purpose of program report result closer user answers along percentage of how close is. instance since there no result matches 100% user answers program should report results match more answers possible (above threshold eg 50%). in specific case program should report follow results:

=> r3 75% (since there 3 matches on 4 questions)

=> r1 50% (since there 2 matches on 4 questions)

notice r4 has 1 match (so 25%) whereas r2 , r5 have no matches @ (so 0%). main issue on implementing above program there lot of questions (approximately 30) number of answers each (3-4 answers each). not aware of efficient algorithm can retrieve results closer user answers. notice way these results stored not important @ all. can assume results stored in relational database , sql query used retrieve them.

the solution can think of perform exhaustive search not efficient @ all. in other words thinking following:

=> first try retrieve results match user answers: {qa = a4, qb = b1, qc = c1, qd = d1}

=> if no results exist change option of question (eg qa) , try again. example try: {qa = a1, qb = b1, qc = c1, qd = d1}

=> if there still nothing try rest possible options qa eg a2, a3

=> if there still nothing give qa initial user answer (that a4) , move qb similar. example try like: {qa = a4, qb = b2, qc = c1, qd = d1}

=> if after trying possible options questions 1 one there results try changing options of combinations of questions. example try change options of 2 questions @ same time (eg qa , qb): {qa = a1, qb = b2, qc = c1, qd = d1}

=> try combinations of 3 questions , on...

clearly above algorithm extremely slow on large number of questions. there known algorithm or heuristic more efficient above algorithm?

thanks in advance

"only" 30 questions?
following "stupid" algorithm faster highly "intelligent" , complicated algorithm.

iterate on characteristics     score = 0     iterate on questions         if questions's answer right in current characteristic             score++ 

then add variable keeps track of maximum value , matching characteristic , set.

runtime size of characteristics * size of questions, whereas algorithm describing can have exponential runtime, , on top of more complicated both programming , executing (due effects branch misprediction)


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -