0

I need to design an online exam server for an exam like GRE in which question difficulty increases if you answer correctly and decreases if you answer wrong.

Questions are multiple choice questions

Difficulty scale of question is 1-10, 1 being the easiest and 10 being the hardest.

If two continuous questions are answered wrong, decrease the difficulty by 1 and if two questions answered right increase the difficulty by 1.

Test starts with a question of difficulty level of 4.

Question carries marks equal to its difficulty.

My question is: Which data structure should I use to store the questions? Which is the best algorithm to fetch the question by its difficulty, etc.?

I am currently considering a doubly linked-list:

struct node {

    int data;
    node *prev;
    node *next;
    int n
    int MAX;
};

Here, 2 n's we need to store. One is MAX (actual size) and n is possible random size to pick questions from n - MAX we selected already for each double linked list you can add extra int data where you can store prev link, next link, pointer to array, int Maxdata(MAX size), int n(current size).

Each node is a pointer to an array of questions for each level. If the answer is correct, it moves next node and picks the random questions from that list, otherwise it moves to the previous node and picks a question.

For example, let's say an array has 10 questions 1 - 10. Since the array size is n = 10, you know that

  1. now you selected a random question rand() % 10 = 6 th questions
  2. now swap the question number 6 & 10, make n-- and return the 6th question
  3. now n = 9 so next time 10th will not be considered
  4. random will return 1 - 9 only

Is there any better way of doing it?

migrated from codereview.stackexchange.com Dec 27 '13 at 17:06

This question came from our site for peer programmer code reviews.

  • I would use a SQL database. You're going to need a data store anyway, and a database will give you the querying capability you need. Looks like you're programming in C; consider SQLite. – Robert Harvey Dec 27 '13 at 17:07
  • Can you please provide a schema for the DB. – PythonEnthusiast Dec 27 '13 at 17:10
  • Please. This question was asked me in an interview. I gave this answer. I want to know the other solutions as well. – PythonEnthusiast Dec 27 '13 at 17:14
  • 1
    @user1162512 you may wish to read Why do interview questions make poor programmers.SE questions – user40980 Dec 27 '13 at 17:49
1

A database table for your questions might look like this:

QuestionID          PK
Question            Text
Difficulty          Int

Keep track of the questions already asked and answered in another table:

StudentID           FK
TestID              FK
QuestionID          FK
AnswerID            FK  (assumes multiple choice)

Possible answers to questions (multiple choice):

AnswerID            PK
QuestionID          FK
Answer              Text
IsTheCorrectAnswer  boolean

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.