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
- now you selected a random question rand() % 10 = 6 th questions
- now swap the question number 6 & 10, make n-- and return the 6th question
- now n = 9 so next time 10th will not be considered
- random will return 1 - 9 only
Is there any better way of doing it?